A stack_allocator that can get other allocators as template parameter and use the stack first and when it ran out of stack, uses the parent allocator. Parent allocator should be defaulted to std::allocator so it doesn't hold any burden on the stack size.
The usage is something like this:
using allocator_type = stack_allocator<std::allocator<void(*)()>, 1>; // stack size = 1 * sizeof(void(*)())
using func = istl::function<void(), allocator_type>;
using vec_alloc = stack_allocator<std::allocator<func>, 5>; // a stack good for 5 functions
vector<func, vec_alloc> routes;
The point of this is to put the burden of implementing Small Object Optimization technique on the allocator and not the object itself.
A stack_allocator that can get other allocators as template parameter and use the stack first and when it ran out of stack, uses the parent allocator. Parent allocator should be defaulted to
std::allocator
so it doesn't hold any burden on the stack size.The usage is something like this:
The point of this is to put the burden of implementing Small Object Optimization technique on the allocator and not the object itself.
See also: