Boost logo

Boost Users :

Subject: [Boost-users] [Fwd: boost::function Small Buffer Optimization (SBO) and allocators]
From: Chris Hite (C.Hite_at_[hidden])
Date: 2009-12-04 06:18:44


I would really like to specify the SBO size on boost::function! How

about changing the signature to?:
template<typename Signature,std::size_t SBOSize=3*sizeof(void*)>
class function;

I've been trying to do a work around using the constructor with the
allocator. I was going to define my own function class derived from the
boost one, with a private one time allocator using a private buffer.
This approach works find as long as constructors where the Functor type
is present.

The copy constructor and equals operators require serious hackery, since
these constructors on boost function don't allow you to pass a new allow
you to pass a new allocator. There's no
  template<typename Allocator>
  functionN(const functionN&, Allocator);

This means that the Function constructor has to affect data underlying
the const Function instance it's copying such that when the allocator is
copied over it mutates into one that points at the private buffer of the
new constructing instance.

This is doable, but kind of scary since I'm making assumptions about
when and how the Allocator is copied.

This is also not such a wonderful solution, because the SBO is wasted.

Any chance of just parameterizing the SBO size?

Chris


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