Boost logo

Boost Users :

From: David Williams (david_at_[hidden])
Date: 2006-02-18 05:50:36


me22 wrote:
> On 2/17/06, David Williams <david_at_[hidden]> wrote:
>
>> But what should SomeTypeHere actually be? I've found I can use
>> boost::function but would rather not for performance reasons. Any other
>> options?
>>
>>
>
> Are you sure function is too slow?
>
> - Function object wrapper size
> Function object wrappers will be the size of two function pointers
> plus one function pointer or data pointer (whichever is larger). On
> common 32-bit platforms, this amounts to 12 bytes per wrapper.
> Additionally, the function object target will be allocated on the
> heap.
>
> - Copying efficiency
> Copying function object wrappers may require allocating memory for a
> copy of the function object target. The default allocator may be
> replaced with a faster custom allocator or one may choose to allow the
> function object wrappers to only store function object targets by
> reference (using ref) if the cost of this cloning becomes prohibitive.
>
> - Invocation efficiency
> With a properly inlining compiler, an invocation of a function object
> requires one call through a function pointer. If the call is to a free
> function pointer, an additional call must be made to that function
> pointer (unless the compiler has very powerful interprocedural
> analysis).
> ~ http://www.boost.org/doc/html/function/misc.html#id2699622
>
> The size of a function is roughly the same as storing a smart pointer
> and a member function pointer. Calling through a function pointer is
> roughly the same as a virtual function call. I don't think you can
> get more speed without losing genericity.
>
> The only possibility I can think of would be something akin to the
> mutable-members-in-a-reference-to-temporary trick used in ScopeGuard (
> http://www.cuj.com/documents/s=8000/cujcexp1812alexandr/alexandr.htm
> ), but that's very narrowly applicable.
>
> ~ Scott
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>
Hmmm... yes I agree the overhead of boost::function is very low (and
it's also the most elegant approach) but it does appear to make a
difference as I am using it to call a very low cost method (an accessor
for a class). But I think this probably is a design error on my part. I
think the best approach is for me to adjust my code to use it in a more
appropriate way.

Thanks anyway!

David


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net