Autonomy Software C++ 24.5.1
Welcome to the Autonomy Software repository of the Mars Rover Design Team (MRDT) at Missouri University of Science and Technology (Missouri S&T)! API reference contains the source code and other resources for the development of the autonomy software for our Mars rover. The Autonomy Software project aims to compete in the University Rover Challenge (URC) by demonstrating advanced autonomous capabilities and robust navigation algorithms.
Loading...
Searching...
No Matches
duckdb::ArenaAllocator Class Reference
Collaboration diagram for duckdb::ArenaAllocator:

Public Member Functions

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 ArenaChunkGetHead ()
 
DUCKDB_API ArenaChunkGetTail ()
 
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")
 
AllocatorGetAllocator ()
 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 Public Attributes

static constexpr const idx_t ARENA_ALLOCATOR_INITIAL_CAPACITY = 2048
 
static constexpr const idx_t ARENA_ALLOCATOR_MAX_CAPACITY = 1ULL << 24ULL
 

Private Member Functions

void AllocateNewBlock (idx_t min_size)
 

Private Attributes

Allocatorallocator
 Internal allocator that is used by the arena allocator.
 
idx_t initial_capacity
 
unsafe_unique_ptr< ArenaChunkhead
 
ArenaChunktail
 
Allocator arena_allocator
 An allocator wrapper using this arena allocator.
 
idx_t allocated_size = 0
 The total allocated size.
 

Member Function Documentation

◆ 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 }

◆ 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 }

◆ GetAllocator()

Allocator & duckdb::ArenaAllocator::GetAllocator ( )
inline

Returns an "Allocator" wrapper for this arena allocator.

9548 {
9549 return arena_allocator;
9550 }
Allocator arena_allocator
An allocator wrapper using this arena allocator.
Definition duckdb.hpp:9597

◆ 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());
9572 const auto size = static_cast<uint32_t>(len);
9573 if (!String::CanBeInlined(size)) {
9574 // If the string can't be inlined, we allocate it on the arena allocator
9575 mem = AllocateAligned(sizeof(char) * size + 1); // +1 for null terminator
9576 memcpy(mem, data, size);
9577 mem[size] = '\0';
9578 }
9579
9580 return String::Reference(mem ? reinterpret_cast<char *>(mem) : data, size);
9581 }
GOpaque< Size > size(const GMat &src)
::uint32_t uint32_t

◆ MakeString() [2/2]

String duckdb::ArenaAllocator::MakeString ( const std::string &  data)
inline
9583 {
9584 return MakeString(data.c_str(), data.size());
9585 }

The documentation for this class was generated from the following file: