Signet Forge 0.1.0
C++20 Parquet library with AI-native extensions
DEMO
Loading...
Searching...
No Matches
signet::forge::Arena Class Reference

Bump-pointer arena allocator for batch Parquet reads. More...

#include <memory.hpp>

Public Member Functions

 Arena (size_t block_size=64 *1024)
 Construct an arena with the given default block size.
 
 ~Arena ()=default
 
void * allocate (size_t size, size_t alignment=8)
 Allocate aligned memory from the arena.
 
void * allocate_zeroed (size_t size, size_t alignment=alignof(std::max_align_t))
 Allocate zero-initialized memory from the arena.
 
template<typename T >
T * allocate_array (size_t count)
 Allocate a typed array of count elements from the arena.
 
const uint8_t * copy (const uint8_t *data, size_t size)
 Copy raw bytes into the arena and return a pointer to the copy.
 
const char * copy_string (const std::string &str)
 Copy a string into the arena (including null terminator).
 
size_t bytes_used () const
 Total bytes allocated (excluding alignment padding).
 
void reset ()
 Reset the arena, reusing all memory blocks without freeing them.
 
 Arena (const Arena &)=delete
 Non-copyable.
 
Arenaoperator= (const Arena &)=delete
 Non-copyable.
 
 Arena (Arena &&) noexcept=default
 Move-constructible.
 
Arenaoperator= (Arena &&) noexcept=default
 Move-assignable.
 

Detailed Description

Bump-pointer arena allocator for batch Parquet reads.

Maintains a list of memory blocks. Allocations bump a pointer within the current block; when a block is exhausted a new one is allocated. reset() recycles all blocks without freeing, making them available for reuse.

Non-copyable, movable. Thread-safety: not thread-safe – callers must synchronize externally if shared across threads.

See also
ColumnReader (primary consumer for zero-copy page decoding)

Definition at line 33 of file memory.hpp.

Constructor & Destructor Documentation

◆ Arena() [1/3]

signet::forge::Arena::Arena ( size_t  block_size = 64 * 1024)
inlineexplicit

Construct an arena with the given default block size.

Parameters
block_sizeDefault allocation block size in bytes (default 64 KiB).

Definition at line 37 of file memory.hpp.

◆ ~Arena()

signet::forge::Arena::~Arena ( )
default

◆ Arena() [2/3]

signet::forge::Arena::Arena ( const Arena )
delete

Non-copyable.

◆ Arena() [3/3]

signet::forge::Arena::Arena ( Arena &&  )
defaultnoexcept

Move-constructible.

Member Function Documentation

◆ allocate()

void * signet::forge::Arena::allocate ( size_t  size,
size_t  alignment = 8 
)
inline

Allocate aligned memory from the arena.

Attempts to satisfy the allocation from the current block. If the current block cannot accommodate the request, a new block is allocated whose size is at least size + alignment or block_size_, whichever is larger.

Parameters
sizeNumber of bytes to allocate (0 returns nullptr).
alignmentRequired alignment (must be a power of 2, default 8).
Returns
Pointer to the allocated memory, or nullptr if size is 0.

Definition at line 52 of file memory.hpp.

◆ allocate_array()

template<typename T >
T * signet::forge::Arena::allocate_array ( size_t  count)
inline

Allocate a typed array of count elements from the arena.

Elements are not constructed (raw memory only). The alignment is derived from alignof(T).

Template Parameters
TElement type.
Parameters
countNumber of elements (0 returns nullptr).
Returns
Pointer to the first element, or nullptr if count is 0.

Definition at line 107 of file memory.hpp.

◆ allocate_zeroed()

void * signet::forge::Arena::allocate_zeroed ( size_t  size,
size_t  alignment = alignof(std::max_align_t) 
)
inline

Allocate zero-initialized memory from the arena.

CWE-908: Use of Uninitialized Resource — zeroing prevents information leaks from recycled arena blocks or stale heap memory.

Equivalent to allocate() followed by memset to zero. Useful for security-sensitive buffers where uninitialized memory could leak data.

Parameters
sizeNumber of bytes to allocate (0 returns nullptr).
alignmentRequired alignment (must be a power of 2, default max_align_t).
Returns
Pointer to zero-filled memory, or nullptr if size is 0.

Definition at line 92 of file memory.hpp.

◆ bytes_used()

size_t signet::forge::Arena::bytes_used ( ) const
inline

Total bytes allocated (excluding alignment padding).

Returns
Cumulative allocation count in bytes.

Definition at line 141 of file memory.hpp.

◆ copy()

const uint8_t * signet::forge::Arena::copy ( const uint8_t *  data,
size_t  size 
)
inline

Copy raw bytes into the arena and return a pointer to the copy.

Parameters
dataSource bytes to copy (nullptr returns nullptr).
sizeNumber of bytes to copy (0 returns nullptr).
Returns
Pointer to the arena-owned copy, or nullptr on empty input.

Definition at line 119 of file memory.hpp.

◆ copy_string()

const char * signet::forge::Arena::copy_string ( const std::string &  str)
inline

Copy a string into the arena (including null terminator).

Parameters
strThe string to copy.
Returns
Pointer to the null-terminated arena-owned copy.

Definition at line 131 of file memory.hpp.

◆ operator=() [1/2]

Arena & signet::forge::Arena::operator= ( Arena &&  )
defaultnoexcept

Move-assignable.

◆ operator=() [2/2]

Arena & signet::forge::Arena::operator= ( const Arena )
delete

Non-copyable.

◆ reset()

void signet::forge::Arena::reset ( )
inline

Reset the arena, reusing all memory blocks without freeing them.

After reset, subsequent allocations reuse existing block memory. This avoids the cost of repeated malloc/free across batches.

Definition at line 147 of file memory.hpp.


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