[C++-sig] pickle the unpickleable

Neal Becker ndbecker2 at gmail.com
Sat Sep 3 13:58:18 CEST 2011


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



More information about the Cplusplus-sig mailing list