15template<
int SIZE,
typename T>
class ccl_try_align(16) StackAllocator {
18 using difference_type = ptrdiff_t;
20 using const_pointer =
const T *;
21 using reference =
T &;
22 using const_reference =
const T &;
27 StackAllocator() : pointer_(0), use_stack_(
true) {}
29 StackAllocator(
const StackAllocator & ) : pointer_(0), use_stack_(
true) {}
32 StackAllocator(
const StackAllocator<SIZE, U> & ) : pointer_(0), use_stack_(
false)
38 T *allocate(
const size_t n,
const void *hint =
nullptr)
44 if (pointer_ + n >=
SIZE || use_stack_ ==
false) {
45 size_t size = n *
sizeof(
T);
48#ifdef WITH_BLENDER_GUARDEDALLOC
51 mem = (
T *)malloc(
size);
54 throw std::bad_alloc();
58 T *mem = &data_[pointer_];
63 void deallocate(
T *p,
const size_t n)
68 if (p < data_ || p >= data_ +
SIZE) {
70#ifdef WITH_BLENDER_GUARDEDALLOC
82 T *address(
T &
x)
const
87 const T *address(
const T &
x)
const
94 void construct(
T *p,
const T &val)
108 size_t max_size()
const
115 template<
class U>
struct rebind {
116 using other = StackAllocator<SIZE, U>;
121 template<
class U> StackAllocator &
operator=(
const StackAllocator<SIZE, U> & )
126 StackAllocator<SIZE, T> &
operator=(
const StackAllocator & )
131 bool operator==(
const StackAllocator & )
const
136 bool operator!=(
const StackAllocator &other)
const