Boost logo

Boost :

From: Jonathan Turkanis (technews_at_[hidden])
Date: 2004-01-20 13:37:57


"Bronek Kozicki" <brok_at_[hidden]> wrote in message
news:006301c3df38$783e7e70$d801a8c0_at_waw.home...
> Jonathan Turkanis <technews_at_[hidden]> wrote:
> > The problem I ran into (I assume its the same one Bronek Kozicki
> > alluded to in his source) has to do with multiple
iheritance.Suppose
>
> Exactly. I did not found it myself, it was Ben Hutchings who pointed
it
> out
>
http://groups.google.com/groups?selm=slrnbtriet.1qo.do-not-spam-benh%40tin.bwsint.com
>
> > You might be able to save a byte or two by storing an offset, but
this
> > relies on implementation defined behavior, and would not be able
to
> > handle really huge objects.
>
> This will give no gain at all in architecture with alignment size
equal
> to (or larger than) pointer size (which is rather popular, I guess).
I
> was thinking to compute and save this offset in compile time, but
then
> there's no way to store it in auto_ptr and pass in compile time
while

Yeah, I though about this. I believe it might save space on some
architectures, though.

Here's a funny solution -- the stored deleter is a pointer into a huge
static array:

    typedef void (*deleter_fn) (void*);

    struct deleter {
          deleter_fn deleter;
          int offset;
    };

    template<typename D, typename T>
    struct deleter_holder {
        typedef deleter (&deleter_array) [SHRT_MAX];
        static deleter_array deleters()
            {
                deleter ar[SHRT_MAX];
                // Initialize on first use, with all possible offsets
in range -SHRT_MAX/2 to SHRT_MAX/2.
                return ar;
            }
        static void destroy(void* pv) { D()((T*) pv); }
    };

Maybe someday this will seem like an innocent use of resources.

Jonathan


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