Boost logo

Boost Users :

Subject: Re: [Boost-users] [Serialization] [Serialization of stl map withpointer to POD type]
From: Denis Gabaidulin (gabaden_at_[hidden])
Date: 2008-12-31 09:32:14


Thank u vÅry much.

In regard to const char * type, i use it just a stupid c-strings, caz
i need maximum performance.
p.s. In my app keys are immutable.

On Wed, Dec 31, 2008 at 05:02, Robert Ramey <ramey_at_[hidden]> wrote:
> Anytime you're serialization a "const" value its a red flag that
> you might really want to do that. "const" values are
> initialized when the object is created and should never
> subsequently change.
>
> anyway, try:
>
> save ..
> ar << data.count();.
> for (iter = data_.begin(); iter != data_.end(); iter++) {
> std::string key(iter->first);
> ar << key;
> ar << iter->second;
> }
>
> load ...
> _data.clear()
> ar >> count;
> while(0 < count){
> std::string key;
> int i;
> ar >> key;
> ar >> i;
> data_.insert(
> key.cstr(), // of course this won't work - but you get the idea
> i
> );
> }
>
> Robert Ramey
>
> Denis Gabaidulin wrote:
>> I have following class with stl container:
>>
>> class storage : {
>> private:
>> map<const char*, int, cmp> data_;
>>
>> friend class boost::serialization::access;
>>
>> template<class Archive>
>> void save(Archive & ar, const unsigned int version) const
>> {
>> map<string, int> local;
>> constDataIter iter;
>>
>> for (iter = data_.begin(); iter != data_.end(); iter++) {
>> local[iter->first] = iter->second;
>> }
>>
>> ar & local;
>> }
>> }
>>
>> This code works, but it slowly(full copy) and consume too much memory
>> (x2) :-(
>>
>> What is the best serialization strategy with such stl containers or
>> pointer to pod type?
>>
>> I cannot change const char* to string, dont ask me why :-))
>>
>> Thanks you for any advice.
>
>
>
> _______________________________________________
> 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