Boost logo

Boost Users :

Subject: [Boost-users] memory overhead of boost::function<>
From: Zachary Turner (divisortheory_at_[hidden])
Date: 2009-08-11 22:56:33


Is there an easy way to calculate the minimum and maximum memory
overhead required by a single instance of boost::function? It's not
easy to trace through the code and find all instances of allocations /
deallocations and member variables. sizeof(boost::function<T>)
appears to be 32 on my machine for all values of T but I'm not sure if
there are certain types of functions which might be less than this or
more than this.

Is there any way to reduce the memory overhead of boost::function? 32
is quite a bit on an x86 architecture, considering a normal function
pointer on the same machine takes only 4 bytes. I was thinking of
using boost::function<> as the basis for a generic inter-object
messaging system where there may be thousands of objects in the
systems any of which might want to communicate via event sinks /
sources implemented via boost::function<> and callback registration.
But if the memory overhead is 32-bytes per object at a minimum, and
possibly more with more complicated function objects or on 64-bit
architectures, then it seems like it could quickly grow out of hand if
there were many listeners.


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