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
void BLI_kdtree_nd_ free(KDTree *tree)
BLI_INLINE bool operator!=(const ListBase &a, const ListBase &b)
bool operator==(const AssetWeakReference &a, const AssetWeakReference &b)
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
btGeneric6DofConstraint & operator=(btGeneric6DofConstraint &other)
#define ccl_try_align(...)
#define CCL_NAMESPACE_END
void util_guarded_mem_alloc(const size_t n)
void util_guarded_mem_free(const size_t n)
void * MEM_mallocN_aligned(size_t len, size_t alignment, const char *str)
void MEM_freeN(void *vmemh)