Krotos Modules 3
Loading...
Searching...
No Matches
nanoflann::PooledAllocator Class Reference

#include <nanoflann.hpp>

Public Member Functions

 PooledAllocator ()
 
 ~PooledAllocator ()
 
void free_all ()
 
void * malloc (const size_t req_size)
 
template<typename T >
T * allocate (const size_t count=1)
 

Public Attributes

Size usedMemory = 0
 
Size wastedMemory = 0
 

Private Types

using Offset = uint32_t
 
using Size = uint32_t
 
using Dimension = int32_t
 

Private Member Functions

void internal_init ()
 

Private Attributes

Size remaining_ = 0
 Number of bytes left in current block of storage.
 
void * base_ = nullptr
 Pointer to base of current block of storage.
 
void * loc_ = nullptr
 Current location in block to next allocate.
 

Static Private Attributes

static constexpr size_t WORDSIZE = 16
 
static constexpr size_t BLOCKSIZE = 8192
 

Detailed Description

Pooled storage allocator

The following routines allow for the efficient allocation of storage in small chunks from a specified pool. Rather than allowing each structure to be freed individually, an entire pool of storage is freed at once. This method has two advantages over just using malloc() and free(). First, it is far more efficient for allocating small objects, as there is no overhead for remembering all the information needed to free each object or consolidating fragmented memory. Second, the decision about how long to keep an object is made at the time of allocation, and there is no need to track down all the objects to free them.

Member Typedef Documentation

◆ Dimension

using nanoflann::PooledAllocator::Dimension = int32_t
private

◆ Offset

using nanoflann::PooledAllocator::Offset = uint32_t
private

◆ Size

using nanoflann::PooledAllocator::Size = uint32_t
private

Constructor & Destructor Documentation

◆ PooledAllocator()

nanoflann::PooledAllocator::PooledAllocator ( )
inline

Default constructor. Initializes a new pool.

◆ ~PooledAllocator()

nanoflann::PooledAllocator::~PooledAllocator ( )
inline

Destructor. Frees all the memory allocated in this pool.

Member Function Documentation

◆ allocate()

template<typename T >
T * nanoflann::PooledAllocator::allocate ( const size_t count = 1)
inline

Allocates (using this pool) a generic type T.

Params: count = number of instances to allocate. Returns: pointer (of type T*) to memory buffer

◆ free_all()

void nanoflann::PooledAllocator::free_all ( )
inline

Frees all allocated memory chunks

◆ internal_init()

void nanoflann::PooledAllocator::internal_init ( )
inlineprivate

◆ malloc()

void * nanoflann::PooledAllocator::malloc ( const size_t req_size)
inline

Returns a pointer to a piece of new memory of the given size in bytes allocated from the pool.

Member Data Documentation

◆ base_

void* nanoflann::PooledAllocator::base_ = nullptr
private

Pointer to base of current block of storage.

◆ BLOCKSIZE

size_t nanoflann::PooledAllocator::BLOCKSIZE = 8192
staticconstexprprivate

◆ loc_

void* nanoflann::PooledAllocator::loc_ = nullptr
private

Current location in block to next allocate.

◆ remaining_

Size nanoflann::PooledAllocator::remaining_ = 0
private

Number of bytes left in current block of storage.

◆ usedMemory

Size nanoflann::PooledAllocator::usedMemory = 0

◆ wastedMemory

Size nanoflann::PooledAllocator::wastedMemory = 0

◆ WORDSIZE

size_t nanoflann::PooledAllocator::WORDSIZE = 16
staticconstexprprivate

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