Boost logo

Boost Users :

Subject: Re: [Boost-users] Boost::Serialize, serializing std::basic_string
From: Jacob Holm (jacobholm_at_[hidden])
Date: 2008-11-06 02:38:56


I looked up the typedef of string;

*typedef basic_string<char, char_traits<char>, allocator<char> >
 string;
*

Then made my own typedef;

*typedef basic_string<char, char_traits<char>, NewAllocator<char> >
** stringWithAllocator;

*

..and registered this with boost in the string.hpp;

*BOOST_CLASS_IMPLEMENTATION(stringWithAllocator,
boost::serialization::primitive_type)*

**

Then the code compiles, but serialization does not work. It seems the
allocator is part of the object when serialized, and since the allocator has
members the size is being calculated wrong. I did a work around using
a *std::vector<char,
NewAllocator<char>>. *This is not as smooth, but does the job.

/Jacob Holm
On Fri, Oct 31, 2008 at 6:38 PM, Robert Ramey <ramey_at_[hidden]> wrote:

> basic_string with your own allocator is not the same type as basic_string
> with
> the default allocator.
>
> Look at hos serialization of std::string is implemented and make your own
> using that as an example.
>
> 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