Boost logo

Boost :

From: Ion Gaztañaga (igaztanaga_at_[hidden])
Date: 2006-02-08 00:59:35


Hi Jeff,

> 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 )
> {
> ...
> }

I see. Anyway, in the first example, if "allocate" throws, segment
destructor will automatically unmap and destroy the segment. If you
think that a one step constructor is better, there is no problem to add
it. Just like fstream can do a default constructor or open the file in
the constructor.

The only minor point is that we have to say if we want to create,
connect or open_or_create the segment in the constructor, so we need an
extra constructor.

> Which brings up the issue that I could not easily find any discussion of
> lifetime requirements in the documentation.

Ok. It's true that the segment must be open while using it but, maybe I
should point out with some lifetime examples.

Thanks,

Ion


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