19 #ifndef PBD_STACK_ALLOCATOR_H
20 #define PBD_STACK_ALLOCATOR_H
22 #include <boost/type_traits/aligned_storage.hpp>
29 # define DEBUG_STACK_ALLOC(...) printf (__VA_ARGS__)
31 # define DEBUG_STACK_ALLOC(...)
36 template <
class T, std::
size_t stack_capacity>
41 typedef typename std::allocator<T>::value_type
value_type;
42 typedef typename std::allocator<T>::size_type
size_type;
44 typedef typename std::allocator<T>::pointer
pointer;
45 typedef typename std::allocator<T>::const_pointer
const_pointer;
46 typedef typename std::allocator<T>::reference
reference;
71 template <
typename U,
size_t other_capacity>
80 DEBUG_STACK_ALLOC (
"Allocate %ld item(s) of size %zu on the stack\n", n,
sizeof (T));
86 return static_cast<pointer> (::operator
new (n *
sizeof (T)));
97 DEBUG_STACK_ALLOC (
"Deallocate: ignored. Item is not at the top of the stack \n");
100 ::operator
delete (p);
106 return std::numeric_limits<size_type>::max () /
sizeof (T);
131 #if __cplusplus > 201103L || defined __clang__
132 template <
class U,
class A>
138 template <
class U,
class A>
153 typedef typename boost::aligned_storage<
sizeof (T) * stack_capacity, 16>::type
align_t;
void construct(U *const p)
boost::aligned_storage< sizeof(T) *stack_capacity, 16 >::type align_t
size_type max_size() const
pointer allocate(size_type n, void *hint=0)
StackAllocator & operator=(const StackAllocator &)
const value_type & const_reference
StackAllocator(const StackAllocator< U, other_capacity > &)
void construct(U *const p, A const &a)
bool pointer_in_buffer(pointer const p)
std::ptrdiff_t difference_type
void deallocate(pointer p, size_type n)
const value_type * const_pointer
bool operator!=(StackAllocator const &a) const
StackAllocator(const StackAllocator &)
bool operator==(StackAllocator const &a) const
#define DEBUG_STACK_ALLOC(...)
StackAllocator< U, stack_capacity > other