srp
software rendering pipeline
Loading...
Searching...
No Matches
Memory allocation

Memory allocation functions. More...

Collaboration diagram for Memory allocation:

Files

file  alloc.c
 
file  alloc.h
 
file  arena.c
 
file  arena_p.h
 
file  arena.h
 
typedef struct SRPArena SRPArena
 
typedef struct SRPArenaBlock SRPArenaBlock
 
typedef struct SRPArena SRPArena
 
#define SRP_DEFAULT_ARENA_CAPACITY   (1024 * 1024)
 
#define ARENA_ALLOC(size)   (arenaAlloc(srpContext.arena, (size)))
 
#define ARENA_CALLOC(size)   (arenaCalloc(srpContext.arena, (size)))
 
#define ARENA_RESET()   (arenaReset(srpContext.arena))
 
void * srpMalloc (unsigned long size)
 
void * srpRealloc (void *p, unsigned long size)
 
static SRPArenaBlocknewBlock (size_t capacity)
 
static size_t neededBlockSize (SRPArena *this, size_t requested)
 
SRPArenanewArena (size_t capacity)
 
void freeArena (SRPArena *this)
 
void * arenaAlloc (SRPArena *this, size_t size)
 
void * arenaCalloc (SRPArena *this, size_t size)
 
void arenaReset (SRPArena *this)
 
#define ALIGN_UP(x, align)   (((x) + ((align) - 1)) & ~((align) - 1))
 
#define ALIGN_8_UP(x)   (ALIGN_UP(x, 8))
 
#define SRP_MALLOC(s)   srpMalloc(s)
 
#define SRP_REALLOC(p, s)   srpRealloc(p, s)
 
#define SRP_FREE(p)   free(p)
 

Detailed Description

Memory allocation functions.

Macro Definition Documentation

◆ ALIGN_UP

#define ALIGN_UP (   x,
  align 
)    (((x) + ((align) - 1)) & ~((align) - 1))

Find such a number A which fulfills the requirements: A % align == 0; A > x

◆ SRP_DEFAULT_ARENA_CAPACITY

#define SRP_DEFAULT_ARENA_CAPACITY   (1024 * 1024)

Default capacity of SRPArena

Typedef Documentation

◆ SRPArena [1/2]

typedef struct SRPArena SRPArena

Opaque definition of SRPArena structure

◆ SRPArena [2/2]

typedef struct SRPArena SRPArena

Blockchain-based arena allocator

◆ SRPArenaBlock

typedef struct SRPArenaBlock SRPArenaBlock

Represents a memory block in the SRPArena

Function Documentation

◆ arenaAlloc()

void * arenaAlloc ( SRPArena this,
size_t  size 
)

Allocate a block of memory in the arena

Parameters
[in]thisPointer to the arena
[in]sizeSize of the block to allocate in bytes
Returns
Pointer to the allocated block

◆ arenaCalloc()

void * arenaCalloc ( SRPArena this,
size_t  size 
)

Allocate a block of memory in the arena, initializing the memory to zero

Parameters
[in]thisPointer to the arena
[in]sizeSize of the block to allocate in bytes
Returns
Pointer to the allocated block

◆ arenaReset()

void arenaReset ( SRPArena this)

Reset the arena, freeing all allocated memory. Does not free the arena itself.

Parameters
[in]thisPointer to the arena

◆ freeArena()

void freeArena ( SRPArena this)

Free the arena and all memory allocated within it

Parameters
[in]thisPointer to the arena, as returned by newArena()

◆ neededBlockSize()

static size_t neededBlockSize ( SRPArena this,
size_t  requested 
)
static

Determine the needed block size for a given requested size. Grows in a 2^x fashion

Parameters
[in]thisPointer to the arena
[in]requestedRequested size in bytes
Returns
Needed block size in bytes

◆ newArena()

SRPArena * newArena ( size_t  capacity)

Create a new arena with given capacity. Should be freed with freeArena()

Parameters
[in]capacityThe capacity of the arena in bytes
Returns
Pointer to the newly created arena

◆ newBlock()

static SRPArenaBlock * newBlock ( size_t  capacity)
static

Allocate new block

Parameters
[in]capacityCapacity of the block in bytes
Returns
Pointer to the newly allocated block

◆ srpMalloc()

void * srpMalloc ( unsigned long  size)

malloc wrapper. Checks its return value and calls abort() if it has returned NULL.

See also
SRP_MALLOC

◆ srpRealloc()

void * srpRealloc ( void *  p,
unsigned long  size 
)

realloc wrapper. Checks its return value and calls abort() if it has returned NULL.

See also
SRP_REALLOC