|
Boost Users : |
Subject: Re: [Boost-users] [serialization] object tracking for shared strings
From: Nils Krumnack (nils_at_[hidden])
Date: 2009-12-17 07:51:59
On Dec 16, 2009, at 6:55 PM, Robert Ramey wrote:
> Nils Krumnack wrote:
>> Hi all,
>> 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.
>
>> I was looking for something like that in the documentation, but
>> wasn't
>> very successful. Any ideas?
>
> your instinct is correct. It's just that std::string is special -
> (its the
> only "special" type with respect to boost serialization). It is
> marked "primitive" so it will never be tracked.
>
> For you're situation the solution is to:
>
> a) make your own string type:
>
> struct my_string : public std::string {
> template<class Archive>
> void serialization(Archive & ar, const unsigned int version){
> ar & base_object<std::string>(*this);
> }
> };
>
> BOOST_SERIALIZATION_TRACKING(my_string, track_always).
>
> Now you have as special string that wil be the same is std::string
> except that this one will be tracked during serialization. Note that
> that keeps normal strings separate from these "special" strings
> so you don't have to worry about having wierd surprises in
> other parts of your executable.
Thanks, I will try to do that.
> If a lot of your strings are duplicated, I think boot::flyweight
> might bear looking into.
Thanks, that would have saved some work. Right what I needed. But it
appears it doesn't have serialization support (as of 1.39). Is that
the usual thing where we pass the buck between the developers of the
different libraries as to who has to implement this functionality?
Particularly for flyweights this would be nice to have, given the
aforementioned problem.
Thanks again,
Nils
>
> Robert Ramey
>
>
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
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