Boost logo

Boost :

From: Giovanni Piero Deretta (gpderetta_at_[hidden])
Date: 2007-08-21 10:07:51

On 8/21/07, Mathias Gaunard <mathias.gaunard_at_[hidden]> wrote:
> Steven Watanabe wrote:
> > 2) function::function can throw
> I don't know how boost::function is implemented, but it should be
> possible that it can only throw if the function object contains state.
> And I think that should seldom happen.
> If it doesn't contain state, it should be possible to fallback to a
> two-pointer representation, where function owns nothing (and thus
> doesn't need to allocate memory) and only references code and context.
> (that is to say, std::nested_function from the lambda proposal)

IIRC the lastest verison of boost::function does exactly that. It uses
a small object optimization for simple functors (like stateless ones
and ptr to member function bound to a 'this' ptr). I do not think it
actually *guarantees* that it will never do dynamic allocations, only
that it will do its best, so probably you can't rely on it. How big is
the small object buffer is probably implementation (and architecture)



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