Boost logo

Boost :

From: Pavel Vozenilek (pavel_vozenilek_at_[hidden])
Date: 2006-02-08 09:26:49


"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);

and

void* p = segment_allocate(1024, shmem::manual_lifetime);

And there could be debug mode flag that checks
the data is deallocated in the same modeit was allocated.

> Which brings up the issue that I could not easily find any discussion of
> lifetime requirements in the documentation.
>
Yes, explicit lifetime info is missing.

/Pavel


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk