Boost logo

Boost Users :

From: Mick Hollins (mick_at_[hidden])
Date: 2005-12-16 00:54:59


Buster wrote:

>I'm looking for an STL-like library that would let me do something
>like the following:
>
>tp::database data;
>tp::map<int, string> map1(data);
>tp::list<float> list1(data);
>
>...
>
> tp::transaction t;
> map1.start_transaction(t);
> list1.start_transaction(t);
>
> map1[5] = "hello"; // does NOT commit to container or database
> list1.push_back(1.0); // does NOT commit either
> t.commit(); // Finally commits to container and database.
> // Without this call, t would call rollback
> // in destructor.
>
>Does anyone know of such a library ? If not, I guess
>I'll have to do some writing.
>
>If I do write it, it seems that using boost serialization
>would save a lot of the work. But I've looked at it and it
>seems to be missing a couple things I need. For one, it seems
>to require that you serialize the entire container each
>time you change one element. Perhaps I'm wrong ?
>
>
The approach I use is to use Berkeley DB for transactional persistence
of each element/object in the database, and boost::serialization for
converting C++ objects to and from the array of bytes that is required
by Berkeley DB. That is, I serialize at the granularity of individuals
objects in the database, rather than serializing the whole database
contents in one go.

>The other problem is that I don't see anything related
>to transactions within the library. This may even
>prevent me from using the library to implement the
>actual serialization of each element, as I wouldn't be
>able to gurantee that the data was NOT written.
>
I serialize an object to an in-memory byte vector first before saving to
the database, so that (along with Berkeley DB) guarantees all-or-nothing
(i.e. atomic) changes to the database.

>Unless
>one can hook up transactional archives to boost serialization ?
>
>Any advice or pointers would be greatly appreciated.
>
>


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net