
Pavel Vozenilek wrote:
"Jeff Flinn" wrote:
I think he's pointing out the lack of RAII. From your first example:
named_shared_object segment;
if(!segment.create("/MySharedMemory", //segment name 65536)){ //segment size in bytes return -1; }
void * shptr = segment.allocate(1024/*bytes to allocate*/);
segment.deallocate(shptr);
I'd rather see:
try { named_shared_object segment("/MySharedMemory",65536);
shmem::shared_ptr lPtr = segment.allocate(1024); } catch( const shmem::exception& aExc ) { ... }
Where the shared_ptr has a deleter calling named_shared_object::deallocate. I'd also think that the 'shared_memory' should not be destructed until the last shmem::shared_ptr is released.
Rather than yet another underdocumented shared pointer with subtly different name it should be:
boost::shared_ptr<void, shmem::deleter> p = segment.allocate(1024);
Yes that was my intent.
and
void* p = segment_allocate(1024, shmem::manual_lifetime);
Did you mean for the above to be a free function? Is there really a need for this? Is there precedent with other boost libs dealing in unsafe raw pointers?
And there could be debug mode flag that checks the data is deallocated in the same modeit was allocated.
By 'mode' do you mean whether the shared_ptr, or raw pointer was returned? Thanks, Jeff