Boost logo

Boost :

From: Philippe A. Bouchard (philippeb_at_[hidden])
Date: 2003-10-12 18:32:31

cppljevans_at_[hidden] wrote:


> shared_ptr does it by having 2 pointers to the object. The first is
> stored in shared_ptr::pn. It points to the start of the object. The
> second, which may point to inside of the object after conversion from
> the most derived class, is shared_ptr::px.

I am going to left shifted_ptr as it is because I'd rather optimize the
pointer to be able to destruct object intantaneously instead of dealing with
"ambiguous non-polymorphic objects" which my former smart pointer
(ptr/ptr.hpp.old) was stucked with. The behaviour will result in a
compile-time error for those uncommon types (with implicit address shifts in
pointer casts) and shall officially be undefined in its definition. We are
close to compiler optimizations about this issue which I prefer to put

In fact:
+ if you want shifted_ptr to deal with container nodes, it will be perfect;
+ if you want shifted_ptr to handle complex widget hierarchies it will be
perfect again because the widgets will be destructed instantaneously (even
for cyclic UI containers);
- if you want shifted_ptr to deal with non-polymorphic objects having
multiple inheritance, you will have compiler errors if you are trying to
cast pointers that require implicit address shifts (this is BTW compiler
dependent so it is undefined behaviour).


As Larry have mentionned:
- class_type<> in "collector_traits.hpp" transforms typenames into a class
type. It is not instanciated, only its sizeof() is taken;
- polymorphic_type<> transforms any type into a polymorphic object. It adds
a virtual table so that its size is changed (for non-polymorphic objects);
- shifted_address<I, J> tries to isolate polymorphic objects from
non-polymorphic ones;
- shifted_impl in "shifted_ptr.hpp" is a simple garbage collector example
(will be replace with better ones);
- shifted_specialized only return specialized behaviour of rc_collector,
gc_collector and os_collector (special initializations, different sharing
behaviours, distinct destruction conditions, etc.);
- "offset.hpp" will be discarded;
- maybe the shifted_header will be replaced by detail::shared_count so that
shifted_ptr could be casted to a shared_ptr... I think it is the way to go.

This smells like perfection.


Boost list run by bdawes at, gregod at, cpdaniel at, john at