$include_dir="/home/hyper-archives/boost-users/include"; include("$include_dir/msg-header.inc") ?>
Subject: [Boost-users] [serialization] object tracking for shared strings
From: Nils Krumnack (nils_at_[hidden])
Date: 2009-12-16 18:48:22
Hi all,
I hope one of you will be able to help me with this:  I am working  
with a data structure that contains a large number of (mostly  
identical) strings.  To save memory I put together a shared memory  
string implementation, which ensures that each string is kept in  
memory only once (implemented through a global map with all strings).   
However, once I write them to disk, I again have n copies of each  
string.  I would really prefer, if I could avoid the space overhead.
At first glance, object tracking seems to be the way to go.  If my  
strings were tracked, there would automatically be only one copy of  
each string.  However I can't quite figure out how.  I don't really  
want to change the global tracking behavior for std::string, since  
that might end up affecting code all over the place.
Serializing pointers would be an option, but then I would have to deal  
with the issue of when to deallocate that object.  I suppose I could  
serialize shared pointers, but then I would have to change my  
implementation to use shared pointers internally.  Alternatively I  
could also wrap a struct around the strings internally and turn on  
tracking for that struct, but again I would have to complicate my  
implementation for the sake of serialization.
What I was hoping to find was some way of telling the archive at the  
point where I am serializing the object, that it should track this one  
object.  I am thinking of something like
   ar & BOOST_SERIALIZATION_TRACK_THIS (mystring);
I was looking for something like that in the documentation, but wasn't  
very successful.  Any ideas?
Thanks in advance for any help,
Nils