Boost logo

Boost :

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

"Bronek Kozicki" <brok_at_[hidden]> wrote in message
> 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
> Exactly. I did not found it myself, it was Ben Hutchings who pointed
> out
> > You might be able to save a byte or two by storing an offset, but
> > relies on implementation defined behavior, and would not be able
> > handle really huge objects.
> This will give no gain at all in architecture with alignment size
> to (or larger than) pointer size (which is rather popular, I guess).
> was thinking to compute and save this offset in compile time, but
> there's no way to store it in auto_ptr and pass in compile time

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.


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