Boost logo

Boost :

From: Ion Gaztañaga (igaztanaga_at_[hidden])
Date: 2006-02-12 09:14:28


Hi Reece,

> If process A is writing data to that block, process B should be aware of
> that and not start reading until process A signals that all the data is
> written (especially if process A is writing the data incrementally).
> Similarly, process A should not be allowed to write to that memory while
> process B is reading from it.
>
> With this in place, transfering C++ objects across processes becomes easy if
> you know the type of object being passed. Boost already has a mechanism to
> do this (serialization), so you could make use of the Boost.Serialization
> library to persist the objects to a shmem memory block rather than a file.
> Therefore, the only thing that the shmem needs to provide is a serialization
> archive that works for its shared memory resources.

You can do that, or you can construct the object directly in shared
memory if both process share the same ABI. In this case there is no
serialization. But this approach is more likely when you want to share
some complex data (for example, a data-base) between all processes.

> What would be nice is if the I/O part of the serialization could be seperate
> from the archive format. (I am not sure this is possible with the current
> serialization library). That way, you could do:
>
> object --> binary archive --> shmem | shmem --> binary archive --> object
>
> or
>
> object --> xml archive --> shmem | shmem --> xml archive --> object
>
> where shmem provides what is needed by the different archives in terms of
> I/O.

Shmem offers two general stream-like classes bufferstream and
vectorstream. The first one directly serializes data via operator << to
an user provided buffer (which can be a shared memory buffer). You are
protected against buffer overflows with classic iostream errors
managing. The second one serializes data via operator << to any
character-vector (a shared memory boost::shmem::vector<> for example.
The difference is that vectorstream reallocates the vector as you insert
data. Take a look at the Shmem documentation in this address:

http://ice.prohosting.com/newfunk/boost/libs/shmem/doc/html/shmem/streams.html

> If shmem provides Boost.Serialization support and iostreams support then it
> would be easy to leverage those libraries to provide the high-level passing
> of objects you describe.

I agree. I would need to see what do I need to have Serialization
support what are the requirements of a Serialization archive.

Regards,

Ion


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