I have a Shared Memory class that will work under solaris, and windows via conditional compilation. solaris provide a function called shmget() which provides info on the shm block I am about to create, namely the number of users attached. I use this to decide whether to memset the memory to zero. Does anyone know a way to see if a handle already exists, or if the file I create already exists. The code I use for WIN32 is...
bool SM::open(unsigned long ident, unsigned long size)
sprintf(ident_, "SMID:%ld__%ld", ident, size);
handle_ = CreateFileMapping((HANDLE)0xFFFFFFFF,
0, size, ident_);
// maybe check if handle_ exists or file existed here.??
if(handle_ == NULL)
map_ = MapViewOfFile(handle_, FILE_MAP_READ |
FILE_MAP_WRITE, 0, 0, 0);
open_ = map_ != NULL;
init_ident = ident;
init_size = size;
cout << "Attached to shared memory" << endl;
// only memset if I created memory.
memset(map_, 0, init_size);
Thanks for any help.