|
Boost : |
From: Felipe Magno de Almeida (felipe.m.almeida_at_[hidden])
Date: 2007-10-03 09:28:46
Hi,
I would like to propose a way that could avoid allocations and would
be customizable too.
A allocator could be aggregated inside the boost.exception hierarchy.
This class could be a template on the number of bytes it would have,
and it would do the SBO for allocators.
struct allocator_base
{
virtual /* all allocator interface */
};
template <std::size_t size>
struct allocator : allocator_base
{
boost::array<char, size> buffer_;
// all boilerpart to handle multiple sizes
};
Then it is possible to dynamic_cast<> to allocator_base, where all
allocations would take place.
That way the allocator would not be allocated in the heap and the user
could customize to a bigger size if it knows it will have to attach
more info to that throwing, or less if it believes to be wasting
space. It could have a partial specialization for 0 too to disable SBO
completely.
I guess objects should be default-constructed and swapped too, to avoid copying.
Regards,
-- Felipe Magno de Almeida
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk