15template<
int SIZE,
typename T>
class ccl_try_align(16) StackAllocator
19 using difference_type = ptrdiff_t;
21 using const_pointer =
const T *;
22 using reference = T &;
23 using const_reference =
const T &;
28 StackAllocator() : pointer_(0), use_stack_(
true) {}
30 StackAllocator(
const StackAllocator & ) : pointer_(0), use_stack_(
true) {}
33 StackAllocator(
const StackAllocator<SIZE, U> & ) : pointer_(0), use_stack_(
false)
39 T *allocate(
const size_t n,
const void *hint =
nullptr)
45 if (pointer_ + n >=
SIZE || use_stack_ ==
false) {
46 size_t size = n *
sizeof(
T);
49#ifdef WITH_BLENDER_GUARDEDALLOC
52 mem = (T *)malloc(
size);
55 throw std::bad_alloc();
59 T *mem = &data_[pointer_];
64 void deallocate(T * p,
const size_t n)
69 if (p < data_ || p >= data_ +
SIZE) {
71#ifdef WITH_BLENDER_GUARDEDALLOC
83 T *address(T &
x)
const
88 const T *address(
const T &
x)
const
95 void construct(T * p,
const T &val)
109 size_t max_size()
const
116 template<
class U>
struct rebind {
117 using other = StackAllocator<SIZE, U>;
122 template<
class U> StackAllocator &
operator=(
const StackAllocator<SIZE, U> & )
127 StackAllocator<SIZE, T> &
operator=(
const StackAllocator & )
132 bool operator==(
const StackAllocator & )
const
137 bool operator!=(
const StackAllocator &other)
const