|
ADS-IDAC Engine 5.0.0
|
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... | |
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.
|
inlineexplicit |
| capacity_doubles | Number of doubles the buffer holds. It never grows. |
Definition at line 27 of file bump_allocator.hpp.
|
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.
| num_doubles | Length of the slice, in doubles. |
| std::bad_alloc | if 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().
|
inline |
Total size of the buffer, in doubles.
Definition at line 54 of file bump_allocator.hpp.
References buffer_.
|
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_.
|
inline |
Doubles handed out since construction or the last reset().
Definition at line 56 of file bump_allocator.hpp.
References offset_.
|
private |
Definition at line 59 of file bump_allocator.hpp.
Referenced by allocate(), and capacity().
|
private |
index of the next free double in buffer_
Definition at line 60 of file bump_allocator.hpp.
Referenced by allocate(), reset(), and used().