Boost logo

Boost :

From: Giovanni Piero Deretta (gpderetta_at_[hidden])
Date: 2007-06-05 05:42:03


On 6/5/07, Hervé Brönnimann <hervebronnimann_at_[hidden]> wrote:
> [...]
> Btw, the overhead you add by this technique is a virtual function
> call for all management-related functions (cloning, destroying, etc.)
> including for functions which do not care about allocator (function
> pointers, member functions and functors with small buffer
> optimization). In fact, I think that this cost may be undesirable at
> several levels because it also will prevent a number of optimizations
> since polymorphic dispatch cuts the compiler off from compile-time
> resolution.

Aren't these operations (cloning, destroying, invocation, etc.)
already currently implemented using a set of function pointers (at
least they were last time I looked)? I do not think there is any
significant
performance difference between a call through a function pointer an
though a virtual function (may be a couple extra instructions to fetch
the address from the vtable).

The biggest performance hit with both function pointers and virtual
functions is the fact that is very hard for the compiler to inline
them and thus require a badly predictable indirect jump. I wouldn't be
surprised if compilers were better at inlining virtuals than pointers.

Anyways, I do not think that the allocator trick require virtual
functions, probably the existing type erasure can be used to also
accommodate the allocator.

> So it may be best to provide two function class
> templates, one without and one with allocators.

Oh, no please! What makes boost::function (and shared_ptr btw) very good
is the "one type fits all" design that allows it to be passed between
unrelated libraries. Let's keep it that way.

gpd


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