|
| DUCKDB_API | ArenaAllocator (Allocator &allocator, idx_t initial_capacity=ARENA_ALLOCATOR_INITIAL_CAPACITY) |
| data_ptr_t | Allocate (idx_t len) |
| DUCKDB_API data_ptr_t | Reallocate (data_ptr_t pointer, idx_t old_size, idx_t size) |
| DUCKDB_API data_ptr_t | AllocateAligned (idx_t size) |
| DUCKDB_API data_ptr_t | ReallocateAligned (data_ptr_t pointer, idx_t old_size, idx_t size) |
| DUCKDB_API void | AlignNext () |
| | Increment the internal cursor (if required) so the next allocation is guaranteed to be aligned to 8 bytes.
|
| DUCKDB_API void | ShrinkHead (idx_t shrink_size) const |
| DUCKDB_API void | Reset () |
| | Resets the current head and destroys all previous arena chunks.
|
| DUCKDB_API void | Destroy () |
| DUCKDB_API void | Move (ArenaAllocator &allocator) |
| DUCKDB_API ArenaChunk * | GetHead () |
| DUCKDB_API ArenaChunk * | GetTail () |
| DUCKDB_API bool | IsEmpty () const |
| DUCKDB_API idx_t | SizeInBytes () const |
| | Get the total used size (not cached).
|
| DUCKDB_API idx_t | AllocationSize () const |
| | Get the currently allocated size in bytes (cached, read from "allocated_size").
|
| Allocator & | GetAllocator () |
| | Returns an "Allocator" wrapper for this arena allocator.
|
| template<class T, class... ARGS> |
| T * | Make (ARGS &&... args) |
| template<class T, class... ARGS> |
| arena_ptr< T > | MakePtr (ARGS &&... args) |
| template<class T, class... ARGS> |
| unsafe_arena_ptr< T > | MakeUnsafePtr (ARGS &&... args) |
| String | MakeString (const char *data, const size_t len) |
| String | MakeString (const std::string &data) |
|
|
static constexpr const idx_t | ARENA_ALLOCATOR_INITIAL_CAPACITY = 2048 |
|
static constexpr const idx_t | ARENA_ALLOCATOR_MAX_CAPACITY = 1ULL << 24ULL |
|
|
Allocator & | allocator |
| | Internal allocator that is used by the arena allocator.
|
|
idx_t | initial_capacity |
|
unsafe_unique_ptr< ArenaChunk > | head |
|
ArenaChunk * | tail |
|
Allocator | arena_allocator |
| | An allocator wrapper using this arena allocator.
|
|
idx_t | allocated_size = 0 |
| | The total allocated size.
|
◆ ArenaAllocator()
| duckdb::ArenaAllocator::ArenaAllocator |
( |
Allocator & | allocator, |
|
|
idx_t | initial_capacity = ARENA_ALLOCATOR_INITIAL_CAPACITY ) |
|
explicit |
386096 arena_allocator(ArenaAllocatorAllocate, ArenaAllocatorFree, ArenaAllocateReallocate,
386097 make_uniq<ArenaAllocatorData>(*this)) {
386098 head = nullptr;
386099 tail = nullptr;
386100}
Allocator arena_allocator
An allocator wrapper using this arena allocator.
Definition duckdb.hpp:9597
Allocator & allocator
Internal allocator that is used by the arena allocator.
Definition duckdb.hpp:9592
◆ ~ArenaAllocator()
| duckdb::ArenaAllocator::~ArenaAllocator |
( |
| ) |
|
◆ Allocate()
| data_ptr_t duckdb::ArenaAllocator::Allocate |
( |
idx_t | len | ) |
|
|
inline |
9508 {
9509 D_ASSERT(!head || head->current_position <= head->maximum_size);
9510 if (!head || head->current_position + len > head->maximum_size) {
9511 AllocateNewBlock(len);
9512 }
9513 D_ASSERT(head->current_position + len <= head->maximum_size);
9514 auto result = head->data.get() + head->current_position;
9515 head->current_position += len;
9516 return result;
9517 }
◆ Reallocate()
| data_ptr_t duckdb::ArenaAllocator::Reallocate |
( |
data_ptr_t | pointer, |
|
|
idx_t | old_size, |
|
|
idx_t | size ) |
386138 {
386139 D_ASSERT(head);
386140 if (old_size == size) {
386141
386142 return pointer;
386143 }
386144
386145 const auto head_ptr = head->data.get() + head->current_position - old_size;
386146 int64_t current_position = NumericCast<int64_t>(head->current_position);
386147 int64_t diff = NumericCast<int64_t>(size) - NumericCast<int64_t>(old_size);
386148 if (pointer == head_ptr &&
386149 (size < old_size || current_position + diff <= NumericCast<int64_t>(head->maximum_size))) {
386150
386151 head->current_position = NumericCast<idx_t>(current_position + diff);
386152 return pointer;
386153 } else {
386154
386155 auto result = Allocate(size);
386156 memcpy(result, pointer, old_size);
386157 return result;
386158 }
386159}
◆ AllocateAligned()
| data_ptr_t duckdb::ArenaAllocator::AllocateAligned |
( |
idx_t | size | ) |
|
386168 {
386171}
DUCKDB_API void AlignNext()
Increment the internal cursor (if required) so the next allocation is guaranteed to be aligned to 8 b...
Definition duckdb.cpp:386161
static T AlignValue(T n)
Align value (ceiling) (not for pointer types).
Definition duckdb.hpp:2126
◆ ReallocateAligned()
| data_ptr_t duckdb::ArenaAllocator::ReallocateAligned |
( |
data_ptr_t | pointer, |
|
|
idx_t | old_size, |
|
|
idx_t | size ) |
◆ AlignNext()
| void duckdb::ArenaAllocator::AlignNext |
( |
| ) |
|
Increment the internal cursor (if required) so the next allocation is guaranteed to be aligned to 8 bytes.
386161 {
386162 if (head && !ValueIsAligned<idx_t>(head->current_position)) {
386163
386165 }
386166}
◆ ShrinkHead()
| DUCKDB_API void duckdb::ArenaAllocator::ShrinkHead |
( |
idx_t | shrink_size | ) |
const |
|
inline |
This shrinks the LAST allocation that was made using the allocator Note that we can ONLY safely call this method if Allocate has been called previously with a size >= shrink_size
9528 {
9529 D_ASSERT(head && head->current_position >= shrink_size);
9530 head->current_position -= shrink_size;
9531 }
◆ Reset()
| void duckdb::ArenaAllocator::Reset |
( |
| ) |
|
Resets the current head and destroys all previous arena chunks.
386178 {
386179 if (head) {
386180
386181 if (head->next) {
386182 auto current_next = std::move(head->next);
386183 while (current_next) {
386184 current_next = std::move(current_next->next);
386185 }
386186 }
386187 tail = head.get();
386188
386189
386190 head->current_position = 0;
386191 head->prev = nullptr;
386192 }
386194}
idx_t allocated_size
The total allocated size.
Definition duckdb.hpp:9599
◆ Destroy()
| void duckdb::ArenaAllocator::Destroy |
( |
| ) |
|
386196 {
386197 head = nullptr;
386198 tail = nullptr;
386200}
◆ Move()
| void duckdb::ArenaAllocator::Move |
( |
ArenaAllocator & | allocator | ) |
|
386202 {
386203 D_ASSERT(!other.head);
386204 other.tail = tail;
386205 other.head = std::move(head);
386206 other.initial_capacity = initial_capacity;
386208 Destroy();
386209}
◆ GetHead()
386211 {
386212 return head.get();
386213}
◆ GetTail()
386215 {
386216 return tail;
386217}
◆ IsEmpty()
| bool duckdb::ArenaAllocator::IsEmpty |
( |
| ) |
const |
386219 {
386220 return head == nullptr;
386221}
◆ SizeInBytes()
| idx_t duckdb::ArenaAllocator::SizeInBytes |
( |
| ) |
const |
Get the total used size (not cached).
386223 {
386224 idx_t total_size = 0;
386225 if (!IsEmpty()) {
386226 auto current = head.get();
386227 while (current != nullptr) {
386228 total_size += current->current_position;
386229 current = current->next.get();
386230 }
386231 }
386232 return total_size;
386233}
uint64_t idx_t
a saner size_t for loop indices etc
Definition duckdb.hpp:237
◆ AllocationSize()
| idx_t duckdb::ArenaAllocator::AllocationSize |
( |
| ) |
const |
Get the currently allocated size in bytes (cached, read from "allocated_size").
◆ GetAllocator()
| Allocator & duckdb::ArenaAllocator::GetAllocator |
( |
| ) |
|
|
inline |
Returns an "Allocator" wrapper for this arena allocator.
◆ Make()
template<class T, class... ARGS>
| T * duckdb::ArenaAllocator::Make |
( |
ARGS &&... | args | ) |
|
|
inline |
9553 {
9554 auto mem = AllocateAligned(sizeof(T));
9555 return new (mem) T(std::forward<ARGS>(args)...);
9556 }
◆ MakePtr()
template<class T, class... ARGS>
| arena_ptr< T > duckdb::ArenaAllocator::MakePtr |
( |
ARGS &&... | args | ) |
|
|
inline |
9559 {
9560 return arena_ptr<T>(Make<T>(std::forward<ARGS>(args)...));
9561 }
◆ MakeUnsafePtr()
template<class T, class... ARGS>
| unsafe_arena_ptr< T > duckdb::ArenaAllocator::MakeUnsafePtr |
( |
ARGS &&... | args | ) |
|
|
inline |
9564 {
9565 return unsafe_arena_ptr<T>(Make<T>(std::forward<ARGS>(args)...));
9566 }
◆ MakeString() [1/2]
| String duckdb::ArenaAllocator::MakeString |
( |
const char * | data, |
|
|
const size_t | len ) |
|
inline |
9568 {
9569 data_ptr_t mem = nullptr;
9570
9571 D_ASSERT(len < NumericLimits<uint32_t>::Maximum());
9573 if (!String::CanBeInlined(size)) {
9574
9575 mem = AllocateAligned(sizeof(char) * size + 1);
9576 memcpy(mem, data, size);
9578 }
9579
9580 return String::Reference(mem ? reinterpret_cast<char *>(mem) : data, size);
9581 }
GOpaque< Size > size(const GMat &src)
◆ MakeString() [2/2]
| String duckdb::ArenaAllocator::MakeString |
( |
const std::string & | data | ) |
|
|
inline |
9583 {
9584 return MakeString(data.c_str(), data.size());
9585 }
◆ AllocateNewBlock()
| void duckdb::ArenaAllocator::AllocateNewBlock |
( |
idx_t | min_size | ) |
|
|
private |
386105 {
386107
386108 if (!head) {
386109 capacity = initial_capacity;
386110 } else {
386111 capacity = head->maximum_size;
386112 }
386113
386114
386115 if (capacity > ARENA_ALLOCATOR_MAX_CAPACITY) {
386116 capacity = ARENA_ALLOCATOR_MAX_CAPACITY;
386117 }
386118
386119 if (capacity < ARENA_ALLOCATOR_MAX_CAPACITY) {
386120 capacity *= 2;
386121 }
386122
386123
386124 while (capacity < min_size) {
386125 capacity *= 2;
386126 }
386127 auto new_chunk = make_unsafe_uniq<ArenaChunk>(
allocator, capacity);
386128 if (head) {
386129 head->prev = new_chunk.get();
386130 new_chunk->next = std::move(head);
386131 } else {
386132 tail = new_chunk.get();
386133 }
386134 head = std::move(new_chunk);
386136}
The documentation for this class was generated from the following files: