Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
|
Heap arena implementation. More...
#include <heap_arena.h>
Public Member Functions | |
HeapArena () | |
Initialize. More... | |
size_t | num_allocations () const |
Get number of allocated blocks. More... | |
size_t | num_guard_failures () const |
Get number of guard failures. More... | |
virtual void * | allocate (size_t size) |
Allocate memory. More... | |
virtual void | deallocate (void *ptr) |
Deallocate previously allocated memory. More... | |
virtual size_t | compute_allocated_size (size_t size) const |
Computes how many bytes will be actually allocated if allocate() is called with given size. Covers all internal overhead, if any. More... | |
virtual size_t | allocated_size (void *ptr) const |
Returns how many bytes was allocated for given pointer returned by allocate(). Covers all internal overhead, if any. Returns same value as computed by compute_allocated_size(size). More... | |
Public Member Functions inherited from roc::core::IArena | |
template<class T > | |
void | destroy_object (T &object) |
Destroy object and deallocate its memory. More... | |
Static Public Member Functions | |
static void | set_guards (size_t guards) |
Set enabled guards, for all instances. Parameters. More... | |
Heap arena implementation.
Uses malloc() and free().
The memory is always maximum aligned.
Implements three safety measures:
Allocated chunks have the following format:
ChunkHeader contains pointer to the owning arena, checked when returning memory to arena. ChunkCanary contains magic bytes filled when returning memory to user, and checked when returning memory to arena.
Thread-safe.
Definition at line 65 of file heap_arena.h.
roc::core::HeapArena::HeapArena | ( | ) |
Initialize.
|
virtual |
Allocate memory.
Implements roc::core::IArena.
|
virtual |
Returns how many bytes was allocated for given pointer returned by allocate(). Covers all internal overhead, if any. Returns same value as computed by compute_allocated_size(size).
Implements roc::core::IArena.
|
virtual |
Computes how many bytes will be actually allocated if allocate() is called with given size. Covers all internal overhead, if any.
Implements roc::core::IArena.
|
virtual |
Deallocate previously allocated memory.
Implements roc::core::IArena.
size_t roc::core::HeapArena::num_allocations | ( | ) | const |
Get number of allocated blocks.
size_t roc::core::HeapArena::num_guard_failures | ( | ) | const |
Get number of guard failures.
|
static |
Set enabled guards, for all instances. Parameters.
guards
defines options to modify behaviour as indicated in HeapArenaGuard