libGimbal 0.1.0
C17-Based Extended Standard Library and Cross-Language Runtime Framework
Loading...
Searching...
No Matches
gimbal_arena_allocator.h File Reference

Go to the source code of this file.

Data Structures

struct  GblArenaAllocatorPage
 
struct  GblArenaAllocatorClass
 
struct  GblArenaAllocator
 
struct  GblArenaAllocatorState
 

Macros

#define GblArenaAllocator_construct(...)
 
#define GblArenaAllocator_alloc(...)
 
Type System

Type UUID and cast operators

#define GBL_ARENA_ALLOCATOR_TYPE
 
#define GBL_ARENA_ALLOCATOR(self)
 
#define GBL_ARENA_ALLOCATOR_CLASS(klass)
 
#define GBL_ARENA_ALLOCATOR_GET_CLASS(self)
 

Functions

GblType GblArenaAllocator_type (void)
 
GBL_RESULT GblArenaAllocator_construct (GblArenaAllocator *pSelf, size_t pageSize, size_t pageAlign, GblArenaAllocatorPage *pInitialPage, GblContext *pCtx)
 
GBL_RESULT GblArenaAllocator_destruct (GblArenaAllocator *pSelf)
 
size_t GblArenaAllocator_pageCount (const GblArenaAllocator *pSelf)
 
size_t GblArenaAllocator_bytesUsed (const GblArenaAllocator *pSelf)
 
size_t GblArenaAllocator_bytesAvailable (const GblArenaAllocator *pSelf)
 
size_t GblArenaAllocator_totalCapacity (const GblArenaAllocator *pSelf)
 
size_t GblArenaAllocator_fragmentedBytes (const GblArenaAllocator *pSelf)
 
float GblArenaAllocator_utilization (const GblArenaAllocator *pSelf)
 
void GblArenaAllocator_saveState (const GblArenaAllocator *pSelf, GblArenaAllocatorState *pState)
 
GBL_RESULT GblArenaAllocator_loadState (GblArenaAllocator *pSelf, const GblArenaAllocatorState *pState)
 
void * GblArenaAllocator_alloc (GblArenaAllocator *pSelf, size_t size, size_t alignment)
 
GBL_RESULT GblArenaAllocator_freeAll (GblArenaAllocator *pSelf)
 

Detailed Description

GblArenaAllocator zone/region/area-based allocator + API.

Arena/zone/region/area-based paged allocator.

GblArenaAllocator is a custom allocator which is useful for when you are allocating a bunch of data dynamically which all has the same shared lifetime. The allocator is created once, then as allocations are requested, it only allocates new memory in per-page incremements rather than for individual allocations. Finally, when you're done, rather than calling delete, you simply destruct the allocator, which frees its pages all at once. This can be SUBSTANTIALLY faster than calling malloc() or new for backing data structures with such allocation patterns.

Note
It's often useful to create the first allocation page as a static buffer somewhere in a source file, so that heap memory isn't even used until it's necessary. Be sure to set the GblArenaAllocatorPage::staticAlloc flag to ensure the allocator does not attempt to free it!
See also
GblArenaAllocatorPage, GblPoolAllocator
Author
Falco Girgis

Definition in file gimbal_arena_allocator.h.

Macro Definition Documentation

◆ GBL_ARENA_ALLOCATOR_TYPE

#define GBL_ARENA_ALLOCATOR_TYPE

Type UUID for GblArenaAllocator.

Definition at line 20 of file gimbal_arena_allocator.h.

◆ GBL_ARENA_ALLOCATOR

#define GBL_ARENA_ALLOCATOR (   self)

Cast a GblInstance to GblArenaAllocator.

Definition at line 21 of file gimbal_arena_allocator.h.

◆ GBL_ARENA_ALLOCATOR_CLASS

#define GBL_ARENA_ALLOCATOR_CLASS (   klass)

Cast a GblClass to GblArenaAllocatorClass.

Definition at line 22 of file gimbal_arena_allocator.h.

◆ GBL_ARENA_ALLOCATOR_GET_CLASS

#define GBL_ARENA_ALLOCATOR_GET_CLASS (   self)

Get a GblArenaAllocatorClass from a GblInstance.

Definition at line 23 of file gimbal_arena_allocator.h.

◆ GblArenaAllocator_construct

#define GblArenaAllocator_construct (   ...)

Definition at line 148 of file gimbal_arena_allocator.h.

◆ GblArenaAllocator_alloc

#define GblArenaAllocator_alloc (   ...)

Definition at line 149 of file gimbal_arena_allocator.h.