43 int64_t debug_allocated_amount_ = 0;
48 constexpr
static inline int64_t large_buffer_threshold = 4096;
59 for (
void *
ptr : owned_buffers_) {
60 allocator_.deallocate(
ptr);
76 const uintptr_t alignment_mask = alignment - 1;
77 const uintptr_t potential_allocation_begin = (current_begin_ + alignment_mask) &
79 const uintptr_t potential_allocation_end = potential_allocation_begin +
size;
81 if (potential_allocation_end <= current_end_) {
83 debug_allocated_amount_ +=
size;
85 current_begin_ = potential_allocation_end;
86 return reinterpret_cast<void *
>(potential_allocation_begin);
88 if (
size <= large_buffer_threshold) {
89 this->allocate_new_buffer(
size + alignment, alignment);
90 return this->
allocate(size, alignment);
92 return this->allocator_large_buffer(
size, alignment);
102 return static_cast<T *
>(this->
allocate(
sizeof(
T),
alignof(
T)));
127 T *value =
new (
buffer)
T(std::forward<Args>(args)...);
151 char *
buffer =
static_cast<char *
>(this->
allocate(alloc_size, 1));
160 void *pointer_buffer = this->
allocate(element_amount *
sizeof(
void *),
alignof(
void *));
161 void *elements_buffer = this->
allocate(element_amount * element_size, element_alignment);
164 void *next_element_buffer = elements_buffer;
166 pointers[i] = next_element_buffer;
167 next_element_buffer =
POINTER_OFFSET(next_element_buffer, element_size);
173 template<
typename T,
typename... Args>
177 n,
sizeof(
T),
alignof(
T));
181 new (
static_cast<void *
>(pointers[i]))
T(std::forward<Args>(args)...);
196 template<
size_t Size,
size_t Alignment>
203 void allocate_new_buffer(
int64_t min_allocation_size,
int64_t min_alignment)
207 if (
buffer.size() >= min_allocation_size) {
218 int64_t size_in_bytes = min_allocation_size;
219 if (size_in_bytes <= large_buffer_threshold) {
221 const int grow_size = 1 << std::min<int>(owned_buffers_.
size() + 6, 20);
222 size_in_bytes =
std::min(large_buffer_threshold,
223 std::max<int64_t>(size_in_bytes, grow_size));
226 void *
buffer = allocator_.allocate(size_in_bytes, min_alignment, __func__);
229 current_end_ = current_begin_ + size_in_bytes;
234 void *
buffer = allocator_.allocate(
size, alignment, __func__);
MINLINE int is_power_of_2_i(int n)
#define POINTER_OFFSET(v, ofs)
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
MutableSpan< T > construct_array_copy(Span< T > src)
MutableSpan< void * > allocate_elements_and_pointer_array(int64_t element_amount, int64_t element_size, int64_t element_alignment)
StringRefNull copy_string(StringRef str)
void provide_buffer(AlignedBuffer< Size, Alignment > &aligned_buffer)
void provide_buffer(void *buffer, uint size)
Span< T * > construct_elements_and_pointer_array(int64_t n, Args &&... args)
MutableSpan< T > allocate_array(int64_t size)
void * allocate(const int64_t size, const int64_t alignment)
destruct_ptr< T > construct(Args &&... args)
constexpr MutableSpan< NewT > cast() const
constexpr T * data() const
constexpr const T * data() const
constexpr int64_t size() const
constexpr bool is_empty() const
void remove_and_reorder(const int64_t index)
void append(const T &value)
IndexRange index_range() const
__kernel void ccl_constant KernelData ccl_global void ccl_global char ccl_global int ccl_global char ccl_global unsigned int ccl_global float * buffer
std::unique_ptr< T, DestructValueAtAddress< T > > destruct_ptr
void uninitialized_copy_n(const T *src, int64_t n, T *dst)
_W64 unsigned int uintptr_t