|
Boost : |
From: Fredrik Blomqvist (fredrik_blomqvist_at_[hidden])
Date: 2004-04-28 18:41:33
Robert Ramey wrote:
> Gennadiy Rozental wrote:
>
>> This is about how I expect it to work. But from this description it's
>> unclear:
>
>> 1. Why would you need to save counter into archive? After all value
>> 10
>> has nothing to do with resulting 5.
>> 2. Why would you need direct access to shared_ptr counter? After all
>> using regular shared_ptr copy would automatically bump it to proper
>> value.
>
> I remember my initial implementation just restored the original state.
> Thinking better of it I made a change to the current system. Now
> that you mention it, it wouldn't seem to need the counter anymore.
> Just for laughs I commented out the serialization of the counter and
> if failed to build the test. I'll have to look into it.
>
Seems promising!
Thinking about smart pointer serialization and how to generalize it,
ie. to allow serialization of any "my_ref_count_ptr", I got this idea.
-How about extending the tracking system with a case something like:
serialization::track_ref_count? (perhaps using a is_smart_ptr<>
traits function).
Based on this tag the serializer would at load time maintain a
map<pointer_value, my_ref_count_ptr<T> > to enable the ref-copy
"bumping" of all the subsequent my_ref_count_ptrs.
Where pointer_value is used as key and obtained by
boost::get_pointer (assumed to be specialized for my_ref_ptr).
This is essentially the same approach I outlined earlier in my reviews
and seems similar to both what Peter Dimov uses and Gennadiy
mentions above.
It would of course require extensions to the code but I think it would
possible to use/adapt the existing pointer code-path to some degree.
Hope this sounds reasonable
// Fredrik Blomqvist
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk