Boost logo

Boost :

From: Jeff Garland (jeff_at_[hidden])
Date: 2004-03-03 09:43:35


On Wed, 3 Mar 2004 15:08:52 +0200, Peter Dimov wrote
> Neal D. Becker wrote:
> >
> > On a slightly different thought: if you use a special allocator with a
> > container, such as vector, that is mmap-based, then serialization
> > would be trivial. I wonder if we can use this?

You can, but only very carefully. The problem is that pointers are not
handled correctly. You cannot assume that an mmap file is reloaded in the
same memory location and hence pointers between objects will be wrong
(including vtable pointers). This is why object databases like ObjectStore
and Objectivity 'swizzle' pointer references when they reload a page from disk.

> This is the moral equivalent of fwrite'ing the vector to disk. It can
> work... for a while... if you don't upgrade the compiler and never change
> the object layout, or if you don't mind all your files being invalidated.
> Some compilers use such a scheme for their precompiled headers, I believe.

Exactly. So actually I think serializing into the memory mapped file provides
a very interesting data store for a broad range of purposes. Using allocators
is much more dangerous.

Jeff


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