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::Allocator Class Reference
Collaboration diagram for duckdb::Allocator:

Public Member Functions

DUCKDB_API Allocator (allocate_function_ptr_t allocate_function_p, free_function_ptr_t free_function_p, reallocate_function_ptr_t reallocate_function_p, unique_ptr< PrivateAllocatorData > private_data)
 
Allocatoroperator= (Allocator &&allocator) noexcept=delete
 
DUCKDB_API data_ptr_t AllocateData (idx_t size)
 
DUCKDB_API void FreeData (data_ptr_t pointer, idx_t size)
 
DUCKDB_API data_ptr_t ReallocateData (data_ptr_t pointer, idx_t old_size, idx_t new_size)
 
AllocatedData Allocate (idx_t size)
 
PrivateAllocatorDataGetPrivateData ()
 

Static Public Member Functions

static data_ptr_t DefaultAllocate (PrivateAllocatorData *private_data, idx_t size)
 
static void DefaultFree (PrivateAllocatorData *private_data, data_ptr_t pointer, idx_t size)
 
static data_ptr_t DefaultReallocate (PrivateAllocatorData *private_data, data_ptr_t pointer, idx_t old_size, idx_t size)
 
static AllocatorGet (ClientContext &context)
 
static AllocatorGet (DatabaseInstance &db)
 
static AllocatorGet (AttachedDatabase &db)
 
static DUCKDB_API AllocatorDefaultAllocator ()
 
static DUCKDB_API shared_ptr< Allocator > & DefaultAllocatorReference ()
 
static bool SupportsFlush ()
 
static optional_idx DecayDelay ()
 
static void ThreadFlush (bool allocator_background_threads, idx_t threshold, idx_t thread_count)
 
static void ThreadIdle ()
 
static void FlushAll ()
 
static void SetBackgroundThreads (bool enable)
 

Private Member Functions

bool ShouldUseDebugInfo () const
 

Private Attributes

allocate_function_ptr_t allocate_function
 
free_function_ptr_t free_function
 
reallocate_function_ptr_t reallocate_function
 
unique_ptr< PrivateAllocatorDataprivate_data
 

Static Private Attributes

static constexpr const idx_t MAXIMUM_ALLOC_SIZE = 281474976710656ULL
 

Constructor & Destructor Documentation

◆ Allocator() [1/2]

duckdb::Allocator::Allocator ( )
32384 : Allocator(Allocator::DefaultAllocate, Allocator::DefaultFree, Allocator::DefaultReallocate, nullptr) {
32385}

◆ Allocator() [2/2]

duckdb::Allocator::Allocator ( allocate_function_ptr_t  allocate_function_p,
free_function_ptr_t  free_function_p,
reallocate_function_ptr_t  reallocate_function_p,
unique_ptr< PrivateAllocatorData private_data 
)
32389 : allocate_function(allocate_function_p), free_function(free_function_p),
32390 reallocate_function(reallocate_function_p), private_data(std::move(private_data_p)) {
32391 D_ASSERT(allocate_function);
32392 D_ASSERT(free_function);
32393 D_ASSERT(reallocate_function);
32394#ifdef DEBUG
32395 if (!private_data) {
32396 private_data = make_uniq<PrivateAllocatorData>();
32397 }
32398 private_data->debug_info = make_uniq<AllocatorDebugInfo>();
32399#endif
32400}

◆ ~Allocator()

duckdb::Allocator::~Allocator ( )
32402 {
32403}

Member Function Documentation

◆ AllocateData()

data_ptr_t duckdb::Allocator::AllocateData ( idx_t  size)
32405 {
32406 D_ASSERT(size > 0);
32407 if (size >= MAXIMUM_ALLOC_SIZE) {
32408 D_ASSERT(false);
32409 throw InternalException("Requested allocation size of %llu is out of range - maximum allocation size is %llu",
32410 size, MAXIMUM_ALLOC_SIZE);
32411 }
32412 auto result = allocate_function(private_data.get(), size);
32413#ifdef DEBUG
32414 if (ShouldUseDebugInfo()) {
32415 private_data->debug_info->AllocateData(result, size);
32416 }
32417#endif
32418 if (!result) {
32419 throw OutOfMemoryException("Failed to allocate block of %llu bytes (bad allocation)", size);
32420 }
32421 return result;
32422}

◆ FreeData()

void duckdb::Allocator::FreeData ( data_ptr_t  pointer,
idx_t  size 
)
32424 {
32425 if (!pointer) {
32426 return;
32427 }
32428 D_ASSERT(size > 0);
32429#ifdef DEBUG
32430 if (ShouldUseDebugInfo()) {
32431 private_data->debug_info->FreeData(pointer, size);
32432 }
32433#endif
32434 free_function(private_data.get(), pointer, size);
32435}

◆ ReallocateData()

data_ptr_t duckdb::Allocator::ReallocateData ( data_ptr_t  pointer,
idx_t  old_size,
idx_t  new_size 
)
32437 {
32438 if (!pointer) {
32439 return nullptr;
32440 }
32441 if (size >= MAXIMUM_ALLOC_SIZE) {
32442 D_ASSERT(false);
32443 throw InternalException(
32444 "Requested re-allocation size of %llu is out of range - maximum allocation size is %llu", size,
32445 MAXIMUM_ALLOC_SIZE);
32446 }
32447 auto new_pointer = reallocate_function(private_data.get(), pointer, old_size, size);
32448#ifdef DEBUG
32449 if (ShouldUseDebugInfo()) {
32450 private_data->debug_info->ReallocateData(pointer, new_pointer, old_size, size);
32451 }
32452#endif
32453 if (!new_pointer) {
32454 throw OutOfMemoryException("Failed to re-allocate block of %llu bytes (bad allocation)", size);
32455 }
32456 return new_pointer;
32457}

◆ Allocate()

AllocatedData duckdb::Allocator::Allocate ( idx_t  size)
inline
8658 {
8659 return AllocatedData(*this, AllocateData(size), size);
8660 }

◆ DefaultAllocate()

data_ptr_t duckdb::Allocator::DefaultAllocate ( PrivateAllocatorData private_data,
idx_t  size 
)
static
32459 {
32460#ifdef USE_JEMALLOC
32461 return JemallocExtension::Allocate(private_data, size);
32462#else
32463 auto default_allocate_result = malloc(size);
32464 if (!default_allocate_result) {
32465 throw std::bad_alloc();
32466 }
32467 return data_ptr_cast(default_allocate_result);
32468#endif
32469}

◆ DefaultFree()

void duckdb::Allocator::DefaultFree ( PrivateAllocatorData private_data,
data_ptr_t  pointer,
idx_t  size 
)
static
32471 {
32472#ifdef USE_JEMALLOC
32473 JemallocExtension::Free(private_data, pointer, size);
32474#else
32475 free(pointer);
32476#endif
32477}

◆ DefaultReallocate()

data_ptr_t duckdb::Allocator::DefaultReallocate ( PrivateAllocatorData private_data,
data_ptr_t  pointer,
idx_t  old_size,
idx_t  size 
)
static
32480 {
32481#ifdef USE_JEMALLOC
32482 return JemallocExtension::Reallocate(private_data, pointer, old_size, size);
32483#else
32484 return data_ptr_cast(realloc(pointer, size));
32485#endif
32486}

◆ GetPrivateData()

PrivateAllocatorData * duckdb::Allocator::GetPrivateData ( )
inline
8669 {
8670 return private_data.get();
8671 }

◆ DefaultAllocator()

Allocator & duckdb::Allocator::DefaultAllocator ( )
static
32493 {
32494 return *DefaultAllocatorReference();
32495}

◆ DefaultAllocatorReference()

shared_ptr< Allocator > & duckdb::Allocator::DefaultAllocatorReference ( )
static
32488 {
32489 static shared_ptr<Allocator> DEFAULT_ALLOCATOR = make_shared_ptr<Allocator>();
32490 return DEFAULT_ALLOCATOR;
32491}

◆ SupportsFlush()

bool duckdb::Allocator::SupportsFlush ( )
static
32505 {
32506#if defined(USE_JEMALLOC) || defined(__GLIBC__)
32507 return true;
32508#else
32509 return false;
32510#endif
32511}

◆ DecayDelay()

optional_idx duckdb::Allocator::DecayDelay ( )
static
32497 {
32498#ifdef USE_JEMALLOC
32499 return NumericCast<idx_t>(JemallocExtension::DecayDelay());
32500#else
32501 return optional_idx();
32502#endif
32503}

◆ ThreadFlush()

void duckdb::Allocator::ThreadFlush ( bool  allocator_background_threads,
idx_t  threshold,
idx_t  thread_count 
)
static
32535 {
32536#ifdef USE_JEMALLOC
32537 if (!allocator_background_threads) {
32538 JemallocExtension::ThreadFlush(threshold);
32539 }
32540#endif
32541 MallocTrim(thread_count * threshold);
32542}

◆ ThreadIdle()

void duckdb::Allocator::ThreadIdle ( )
static
32544 {
32545#ifdef USE_JEMALLOC
32546 JemallocExtension::ThreadIdle();
32547#endif
32548}

◆ FlushAll()

void duckdb::Allocator::FlushAll ( )
static
32550 {
32551#ifdef USE_JEMALLOC
32552 JemallocExtension::FlushAll();
32553#endif
32554 MallocTrim(0);
32555}

◆ SetBackgroundThreads()

void duckdb::Allocator::SetBackgroundThreads ( bool  enable)
static
32557 {
32558#ifdef USE_JEMALLOC
32559 JemallocExtension::SetBackgroundThreads(enable);
32560#endif
32561}

◆ ShouldUseDebugInfo()

bool duckdb::Allocator::ShouldUseDebugInfo ( ) const
inlineprivate
8689 {
8690 return private_data && private_data->free_type != AllocatorFreeType::DOES_NOT_REQUIRE_FREE &&
8691 private_data->debug_info;
8692 }

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