CoastalME (Coastal Modelling Environment)
Simulates the long-term behaviour of complex coastlines
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)
 

Data Fields

Size usedMemory = 0
 
Size wastedMemory = 0
 

Private Types

using Size = size_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.

Definition at line 859 of file nanoflann.hpp.

Member Typedef Documentation

◆ Size

using nanoflann::PooledAllocator::Size = size_t
private

Definition at line 870 of file nanoflann.hpp.

Constructor & Destructor Documentation

◆ PooledAllocator()

nanoflann::PooledAllocator::PooledAllocator ( )
inline

Default constructor. Initializes a new pool.

Definition at line 891 of file nanoflann.hpp.

◆ ~PooledAllocator()

nanoflann::PooledAllocator::~PooledAllocator ( )
inline

Destructor. Frees all the memory allocated in this pool.

Definition at line 896 of file nanoflann.hpp.

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

Definition at line 965 of file nanoflann.hpp.

◆ free_all()

void nanoflann::PooledAllocator::free_all ( )
inline

Frees all allocated memory chunks

Definition at line 899 of file nanoflann.hpp.

Referenced by ~PooledAllocator().

◆ internal_init()

void nanoflann::PooledAllocator::internal_init ( )
inlineprivate

Definition at line 876 of file nanoflann.hpp.

Referenced by free_all(), and PooledAllocator().

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

Definition at line 915 of file nanoflann.hpp.

Referenced by allocate(), and malloc().

Field Documentation

◆ base_

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

Pointer to base of current block of storage.

Definition at line 873 of file nanoflann.hpp.

Referenced by free_all(), internal_init(), and malloc().

◆ BLOCKSIZE

size_t nanoflann::PooledAllocator::BLOCKSIZE = 8192
staticconstexprprivate

Definition at line 862 of file nanoflann.hpp.

Referenced by malloc().

◆ loc_

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

Current location in block to next allocate.

Definition at line 874 of file nanoflann.hpp.

Referenced by malloc().

◆ remaining_

Size nanoflann::PooledAllocator::remaining_ = 0
private

Number of bytes left in current block of storage.

Definition at line 872 of file nanoflann.hpp.

Referenced by internal_init(), and malloc().

◆ usedMemory

Size nanoflann::PooledAllocator::usedMemory = 0

Definition at line 885 of file nanoflann.hpp.

Referenced by internal_init(), and malloc().

◆ wastedMemory

Size nanoflann::PooledAllocator::wastedMemory = 0

Definition at line 886 of file nanoflann.hpp.

Referenced by internal_init(), and malloc().

◆ WORDSIZE

size_t nanoflann::PooledAllocator::WORDSIZE = 16
staticconstexprprivate

Definition at line 861 of file nanoflann.hpp.

Referenced by malloc().


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