std::ext STL (was: Re: design doc on alternative pointer support)

Phil Bouchard philippe@fornux.com
Thu Aug 14 11:14:00 GMT 2008


"Bob Walters" <bob.s.walters@gmail.com> wrote in message 
news:5256839C-741A-449E-9BB0-D3DE70320FE0@gmail.com...

[...]

>> The other function _M_clear() will ne to be rewritten.  It is a 
>> interesting one because the nodes of a list will not disappear if we 
>> delete the first node pointer because the first node still is  refered to 
>> by the second node, etc.  We need to take a better "smart  pointer" 
>> approach here.
>
>
> It's an interesting problem.  In your case, the code needs to cut the 
> links between list nodes, and allow the pointer type to determine when 
> deallocation should occur.  Can the allocator, in your case, address  that 
> concern in its destroy/deallocate methods, or would that require 
> specializing something based on the specific Link_node type?
>
> Soliciting opinions: One thing that might be reasonable is to have the 
> code that is deallocating nodes explicitly set pointers to null prior  to 
> calling deallocate/destroy so that smart pointer approaches can  work by 
> simply making deallocate/destroy into no-ops.  This would not  be too hard 
> to explain (comment) in the code, and I suspect that if  alternative 
> pointer support is enabled, there will be many cases where  people want to 
> use some kind of smart pointer implementation.  Phil,  would this 
> convention work for you?

I can't reply to other issues now but I do have time for this one.  Consider 
the following scenario where we have a container 1 as a list and container 2 
as a stack:

list:
n1 <-> n2 <-> n3 <-> n4

stack:
n1 -> n2 -> n3 -> n4

Now clear() iterates from n1 to n4 in both cases and deletes associates 
nodes.  But if we use smart pointers then if we'll get the entire container 
deleted by deleting n1.  In the case of the list then it will be different 
because n2, n3 and n4 will not be deallocated just by deleting n1 (in case 
of shifted_ptr yes but not shared_ptr).  So I'm still careful here and I 
would like opening this subject before anything else.


Thanks,
-Phil





More information about the Libstdc++ mailing list