← Documentation
ADS-IDAC Engine 5.0.0
bncore::BumpAllocator Class Reference

Fixed-capacity scratch buffer of doubles with pointer-bump allocation. More...

#include <bump_allocator.hpp>

Public Member Functions

 BumpAllocator (std::size_t capacity_doubles)
 
double * allocate (std::size_t num_doubles)
 Reserves the next num_doubles doubles of the buffer. More...
 
void reset ()
 Makes the whole buffer available again. Contents are kept, and every slice handed out before becomes reusable. More...
 
std::size_t capacity () const
 Total size of the buffer, in doubles. More...
 
std::size_t used () const
 Doubles handed out since construction or the last reset(). More...
 

Private Attributes

std::vector< double > buffer_
 
std::size_t offset_
 index of the next free double in buffer_ More...
 

Detailed Description

Fixed-capacity scratch buffer of doubles with pointer-bump allocation.

The buffer is allocated once, zero filled, at construction. allocate() hands out consecutive slices in O(1) by advancing an offset, and reset() makes the whole buffer available again in O(1). Individual slices are never freed. The class takes no locks and has no synchronization, so an instance must not be shared between threads that allocate concurrently.

Definition at line 23 of file bump_allocator.hpp.

Constructor & Destructor Documentation

◆ BumpAllocator()

bncore::BumpAllocator::BumpAllocator ( std::size_t  capacity_doubles)
inlineexplicit
Parameters
capacity_doublesNumber of doubles the buffer holds. It never grows.

Definition at line 27 of file bump_allocator.hpp.

Member Function Documentation

◆ allocate()

double * bncore::BumpAllocator::allocate ( std::size_t  num_doubles)
inline

Reserves the next num_doubles doubles of the buffer.

The slice is zero only if that part of the buffer has not been handed out before: reset() does not clear the contents.

Parameters
num_doublesLength of the slice, in doubles.
Returns
Pointer to the slice. It stays valid for the allocator's lifetime, but after reset() later allocations reuse the same memory.
Exceptions
std::bad_allocif fewer than num_doubles doubles remain.

Definition at line 39 of file bump_allocator.hpp.

References buffer_, and offset_.

Referenced by bncore::Factor::marginalize(), and bncore::Factor::multiply().

Here is the caller graph for this function:

◆ capacity()

std::size_t bncore::BumpAllocator::capacity ( ) const
inline

Total size of the buffer, in doubles.

Definition at line 54 of file bump_allocator.hpp.

References buffer_.

◆ reset()

void bncore::BumpAllocator::reset ( )
inline

Makes the whole buffer available again. Contents are kept, and every slice handed out before becomes reusable.

Definition at line 51 of file bump_allocator.hpp.

References offset_.

◆ used()

std::size_t bncore::BumpAllocator::used ( ) const
inline

Doubles handed out since construction or the last reset().

Definition at line 56 of file bump_allocator.hpp.

References offset_.

Member Data Documentation

◆ buffer_

std::vector<double> bncore::BumpAllocator::buffer_
private

Definition at line 59 of file bump_allocator.hpp.

Referenced by allocate(), and capacity().

◆ offset_

std::size_t bncore::BumpAllocator::offset_
private

index of the next free double in buffer_

Definition at line 60 of file bump_allocator.hpp.

Referenced by allocate(), reset(), and used().


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