14template<
int SIZE,
typename T>
class ccl_try_align(16) StackAllocator
18 typedef ptrdiff_t difference_type;
20 typedef const T *const_pointer;
22 typedef const T &const_reference;
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(
size_t n,
const void *hint = 0)
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,
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 typedef StackAllocator<SIZE, U> other;
121 template<
class U>
inline StackAllocator &
operator=(
const StackAllocator<SIZE, U> &)
126 StackAllocator<SIZE, T> &
operator=(
const StackAllocator &)
131 inline bool operator==(StackAllocator
const & )
const
136 inline bool operator!=(StackAllocator
const &other)
const