It's great that you have a callback in your constructor to initialize the memory at allocation time. You might want to make this callback more C++ friendly either by adding a "user parameter" (an opaque void *) that is passed to the callback. That way, if my CFoo class is creating the shared memory, I can do this:
CSharedMemory* pNewBlock = new CSharedMemory("name", 1024, CFoo::Initializer, this);
/*static*/void CFoo::Initializeer(CSharedMemory* pMem, void* p)
CFoo* This = (CFoo*) p;
// "This" now has access to my CFoo object
Alternatively, if you want to go the "real" OO C++ route, you can make the callback a functor.
Martin Ziacek wrote: It is a lovely idea to pass one more parameter to callback function, however it has nothing to do with C++ at all.
Actually, it is a C++ issue, because it's the only way to get a C-style callback to call an object method (as opposed to a standalong function or a static method).
It seems like a minor thing, until you run across one of the few callbacks in the Windows API (SetTimer) that doesn't let you pass a user parameter, and you have to resort to hackery to get an object method called in response to it.
Last Visit: 31-Dec-99 19:00 Last Update: 3-May-15 4:14