Memory allocation functions.
More...
|
| 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 SRPArenaBlock * | newBlock (size_t capacity) |
| |
| static size_t | neededBlockSize (SRPArena *this, size_t requested) |
| |
| SRPArena * | newArena (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) |
| |
Memory allocation functions.
◆ 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) |
◆ SRPArena [1/2]
◆ SRPArena [2/2]
Blockchain-based arena allocator
◆ SRPArenaBlock
Represents a memory block in the SRPArena
◆ arenaAlloc()
| void * arenaAlloc |
( |
SRPArena * |
this, |
|
|
size_t |
size |
|
) |
| |
Allocate a block of memory in the arena
- Parameters
-
| [in] | this | Pointer to the arena |
| [in] | size | Size 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] | this | Pointer to the arena |
| [in] | size | Size of the block to allocate in bytes |
- Returns
- Pointer to the allocated block
◆ arenaReset()
Reset the arena, freeing all allocated memory. Does not free the arena itself.
- Parameters
-
| [in] | this | Pointer to the arena |
◆ freeArena()
Free the arena and all memory allocated within it
- Parameters
-
| [in] | this | Pointer 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] | this | Pointer to the arena |
| [in] | requested | Requested size in bytes |
- Returns
- Needed block size in bytes
◆ newArena()
Create a new arena with given capacity. Should be freed with freeArena()
- Parameters
-
| [in] | capacity | The capacity of the arena in bytes |
- Returns
- Pointer to the newly created arena
◆ newBlock()
Allocate new block
- Parameters
-
| [in] | capacity | Capacity 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