[interprocess] - Usage of boost::interprocess::open_or_create mode
Hi, I am quite new to boost. Are there any code examples around usage of 'open_or_create' mode for ceating the shared_memory_object? My problem is, after we create a 'shared_memory_object' using 'open_or_create' there is no way to know whether it created 'created' a file or 'opened' an already existing file. We need this apparently, because if we are creating a new file, we have to '*construct<container>("MySharedMemory") *' the file with the desired container, otherwise we have to '* find<container>("MySharedMemory")*'. All the usage examples I could get were only around 'create_only' and then 'open_only' modes.. My idea is to write one single method, that'd use the 'open_or_create' mode so that we don't have to bother.. a sequence of creation and then usage.. I am not sure if I was clear enough in putting my problem across, please feel free to respond with questions. Really appreciate any help around this. Thanks & Regards, Srinivas Gardas
Srinivas Gardas escribió:
Hi, I am quite new to boost. Are there any code examples around usage of 'open_or_create' mode for ceating the shared_memory_object? My problem is, after we create a 'shared_memory_object' using 'open_or_create' there is no way to know whether it created 'created' a file or 'opened' an already existing file. We need this apparently, because if we are creating a new file, we have to '*construct<container>("MySharedMemory") *' the file with the desired container, otherwise we have to '* find<container>("MySharedMemory")*'. All the usage examples I could get were only around 'create_only' and then 'open_only' modes..
Currently there is no way to know that, but you can use "find_or_construct", to construct the needed type if it's not already constructed. If it's not constructed, the function returns a pointer to the constructed object. Regards, Ion
participants (2)
-
Ion Gaztañaga
-
Srinivas Gardas