memory: updated arena_init() docs

arena_init() has been given the parameter `size_t capacity`, however,
docs amd some definitions wasn't changed to reflect this.

The definition MEMORY_CAPACITY was replaced by `size_t capacity` but
it wasn't removed.

Signed-off-by: Ronald Caesar <github43132@proton.me>
This commit is contained in:
Ronald Caesar 2025-08-10 02:06:53 -04:00
parent 84c55b25a9
commit b41e8b9d4f
No known key found for this signature in database
GPG key ID: 04307C401999C596
2 changed files with 14 additions and 17 deletions

View file

@ -9,7 +9,7 @@ memory::arena_t memory::arena_init(size_t capacity)
// TODO(GloriousTaco:memory): Replace malloc with a windows memory mapping API.
#ifdef WIN32
auto data = static_cast<uint8_t*>(malloc(sizeof(uint8_t) * MEMORY_CAPACITY));
auto data = static_cast<uint8_t*>(malloc(sizeof(size_t) * capacity));
#else
void* data = ::mmap(nullptr, capacity, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
if (data == MAP_FAILED)
@ -41,7 +41,7 @@ void memory::arena_reset(memory::arena_t* arena)
ASSERT(nullptr != arena);
ASSERT(nullptr != arena->data);
arena->size = 0;
std::memset(arena->data, POISON_PATTERN, arena->capacity);
(void)std::memset(arena->data, POISON_PATTERN, arena->capacity);
}
void memory::arena_free(memory::arena_t* arena)
{

View file

@ -7,10 +7,6 @@
namespace memory
{
/* Defines the default size (in bytes) for memory arenas created via arena_init() */
#define MEMORY_CAPACITY 20480 // 20 KB
#define POISON_PATTERN 0xAA
/*
@ -41,21 +37,22 @@ typedef struct
/*
* NAME
* arena_init - Initialize a memory arena with default capacity.
* arena_init - Initialize a memory arena with specified capacity.
*
* SYNOPSIS
* arema_t memory::arena_init();
* memory::arena_t memory::arena_init(size_t capacity);
*
* DESCRIPTION
* The function creates and returns a new memory arena instance with a
* pre-allocated capacity. See the definition MEMORY_CAPACITY to change the
* default capacity.
* The function creates and returns a new memory arena instance with the
* specified capacity.
*
* PARAMETERS
* capacity - Size of the memory arena to allocate in bytes
*
* RETURN VALUE
* Returns a valid arema_t object on success.
* Returns a valid memory::arena_t object on success. arena_t->data will be null on failure.
*/
extern memory::arena_t arena_init(size_t capacity);
memory::arena_t arena_init(size_t capacity);
/*
* NAME
* arena_allocate - Allocate memory from a pre-initialized arena.
@ -73,7 +70,7 @@ extern memory::arena_t arena_init(size_t capacity);
* pointer is valid until the arena is reset or destroyed.
*
* NOTES
* Requires arema_t to be initialized with arena_init() or similar.
* Requires arena_t to be initialized with arena_init() or similar.
*/
const void* arena_allocate(arena_t* arena, const std::size_t size);
@ -85,7 +82,7 @@ const void* arena_allocate(arena_t* arena, const std::size_t size);
* void memory::arena_reset(memory::arena_t* arena);
*
* DESCRIPTION
* The function resets the allocation size of a pre-initialized arema_t to zero.
* The function resets the allocation size of a pre-initialized arena_t to zero.
* This effectively "frees" all memory allocated from the arena without
* deallocating the underlying buffer, allowing reuse of the capacity for
* future allocations.
@ -105,7 +102,7 @@ void arena_reset(arena_t* arena);
* void memory::arena_free(memory::arena_t* arena);
*
* DESCRIPTION
* The function releases the memory buffer associated with a arema_t and
* The function releases the memory buffer associated with a arena_t and
* resets its capacity and size to zero. This marks the arena as invalid for
* future allocation unless reinitialized.
*/