On 09/03/2011 04:58 AM, Neal Becker wrote:
I have a pickling problem I suspect is just not possible to solve.

I have some wrappers around boost::random objects.

There is a rng object, which is a single underlying mersenne twister.

There are various distributions.  For example, uniform_real.

Each uniform_real holds a reference to the single, external mt object.

I don't think there's any way to unpickle several instance of uniform_real so
that their references to the (shared) mt object get correctly restored.

Imagine something like this:

class mt;

struct uniform_real {
   mt&  _mt;

   uniform_real (mt&, min, max) ...
};

When unpickled, the internal _mt states are saved and restored correctly, but 2
instances of uniform_real will not share a reference to a single mt object, they
each have their own copy which starts with a copy of the same state (no good).


You might be able to get something working if you use Pickler and Unpickler objects instead of the convenience functions in pickle/cPickle. Check out the "memo" and "persistent_id" attributes in particular (in the Python library reference docs).

Jim
_______________________________________________
Cplusplus-sig mailing list
Cplusplus-sig@python.org
http://mail.python.org/mailman/listinfo/cplusplus-sig

Reply via email to