Boost logo

Boost :

From: Philippe A. Bouchard (philippeb_at_[hidden])
Date: 2002-08-06 12:07:25


(Sorry for the late reply, I was away).

> >I made a different version of ptr<> that handles polymorphic pointers.
> >
> >The speed of the class is mainly depended on the number of distinct new U
> >allocations that are first encountered. Once they are encountered it is
as
> >
> Please explain further what you mean by "distince new U allocations...".
Is
> U the ptr template argument.

For example:
ptr<X> = new (rc()) M;
ptr<X> = new (rc()) M;
ptr<Y> = new (rc()) M;
ptr<X> = new (rc()) N;

contains 2 distinct allocations (M and N).

[...]

> >Thus:
> >+ sizeof(ptr<T>) = sizeof(T *);
> >
> I've tried to figure how this would work without having at least 2
pointers
> in ptr<T>. One to hold the reference count and the other to hold the
> T*. Otherwise, I don't see how ptr can handle multiple inheritance.

The pointer (pointing to the start of the allocated block) is adjusted when
dereferenced depending on its relative position in the class hierarchy.
This offset is calculated when different combinaisons of pointers and
pointees are first encountered.

[...]

> >+ once different associations are made large containers can take
advantage
> >of the memory and speed benefits (pool usage cannot do that);
> >- sizeof(new () T) = sizeof(T) + sizeof(int) * 2;
> >
> I don't understand. This seems to indicate the size of a pointer (i.e.
> new () T)
> is > sizeof(T), but if T contains a pointer, this can't be true.

Sorry about it... It was not well explained:
- sizeof(allocated block of new (rc()) T) = sizeof(T) + sizeof(int) * 2;

> >- speedof(* ptr<T>) = speedof(* T) + C.

The pointer is adjusted just before it is dereferenced. C is really just of
timeof(operator []) + timeof(operator +) in time and is negligible when
virtual functions are called (highly probable when polymorphic hierarchies
are used) and dereferencing is already slow anyway. ptr<> (in ptr.h) will
also use a simplified version when non-polymorphic types will be detected
which will allow a speed increase when dereferenced. For now
non-polymorphic types automatically detected under gcc 2.95 seem to be
simple typenames only, but the only thing that we would need is an explicit
instanciation of __type_traits<M> or another boost::type_traits:: detection
(thanks to Dave for this one).

I'm cleaning up the code according to the manner you might be interested...

Thanks,

Philippe A. Bouchard


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk