dimanche 8 mars 2015

boost::serialization of one instance per unique ID


I'm trying to boost::serialize structures which point to objects (say, of symbol class) implementing an idea of a single-instance-per-unique-<something>. That means, those objects are not created directly, but using a static method symbol::get(). This method retrieves an existing object from some global dictionary or creates a new object if necessary.


Now the hard part is that in my system I have many large structures with pointers to such symbols. The structures don't fit all in the memory at the same time. So I need to sequentially build, preprocess and serialize each of the structures separately. Later I'll deserialize and process structures on request.


Standard boost::serialize methods, namely load(...) and save(...) don't work here. Uppon deserialization of a structure would lost the system-wide uniqueness of symbols and serialization would waste a lot of space (my symbol objects are quite large). I've read the boost docs and found that for nonstandard constructors I can use save_construct_data and load_construct_data functions. But docs say also, the default load_construct_data "just uses the default constructor to initialize previously allocated memory". So again this isn't it.


The question is: how can I bypass this loading function so I can avoid any allocation and use my symbol::get() instead? Or maybe there is a more elegant solution?




Aucun commentaire:

Enregistrer un commentaire