mirror of
https://github.com/pound-emu/pound.git
synced 2025-12-12 10:37:00 +00:00
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:
parent
84c55b25a9
commit
b41e8b9d4f
2 changed files with 14 additions and 17 deletions
|
|
@ -9,7 +9,7 @@ memory::arena_t memory::arena_init(size_t capacity)
|
||||||
|
|
||||||
// TODO(GloriousTaco:memory): Replace malloc with a windows memory mapping API.
|
// TODO(GloriousTaco:memory): Replace malloc with a windows memory mapping API.
|
||||||
#ifdef WIN32
|
#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
|
#else
|
||||||
void* data = ::mmap(nullptr, capacity, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
|
void* data = ::mmap(nullptr, capacity, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
|
||||||
if (data == MAP_FAILED)
|
if (data == MAP_FAILED)
|
||||||
|
|
@ -41,7 +41,7 @@ void memory::arena_reset(memory::arena_t* arena)
|
||||||
ASSERT(nullptr != arena);
|
ASSERT(nullptr != arena);
|
||||||
ASSERT(nullptr != arena->data);
|
ASSERT(nullptr != arena->data);
|
||||||
arena->size = 0;
|
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)
|
void memory::arena_free(memory::arena_t* arena)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -7,10 +7,6 @@
|
||||||
|
|
||||||
namespace memory
|
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
|
#define POISON_PATTERN 0xAA
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -41,21 +37,22 @@ typedef struct
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* NAME
|
* NAME
|
||||||
* arena_init - Initialize a memory arena with default capacity.
|
* arena_init - Initialize a memory arena with specified capacity.
|
||||||
*
|
*
|
||||||
* SYNOPSIS
|
* SYNOPSIS
|
||||||
* arema_t memory::arena_init();
|
* memory::arena_t memory::arena_init(size_t capacity);
|
||||||
*
|
*
|
||||||
* DESCRIPTION
|
* DESCRIPTION
|
||||||
* The function creates and returns a new memory arena instance with a
|
* The function creates and returns a new memory arena instance with the
|
||||||
* pre-allocated capacity. See the definition MEMORY_CAPACITY to change the
|
* specified capacity.
|
||||||
* default capacity.
|
*
|
||||||
|
* PARAMETERS
|
||||||
|
* capacity - Size of the memory arena to allocate in bytes
|
||||||
*
|
*
|
||||||
* RETURN VALUE
|
* 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
|
* NAME
|
||||||
* arena_allocate - Allocate memory from a pre-initialized arena.
|
* 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.
|
* pointer is valid until the arena is reset or destroyed.
|
||||||
*
|
*
|
||||||
* NOTES
|
* 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);
|
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);
|
* void memory::arena_reset(memory::arena_t* arena);
|
||||||
*
|
*
|
||||||
* DESCRIPTION
|
* 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
|
* This effectively "frees" all memory allocated from the arena without
|
||||||
* deallocating the underlying buffer, allowing reuse of the capacity for
|
* deallocating the underlying buffer, allowing reuse of the capacity for
|
||||||
* future allocations.
|
* future allocations.
|
||||||
|
|
@ -105,7 +102,7 @@ void arena_reset(arena_t* arena);
|
||||||
* void memory::arena_free(memory::arena_t* arena);
|
* void memory::arena_free(memory::arena_t* arena);
|
||||||
*
|
*
|
||||||
* DESCRIPTION
|
* 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
|
* resets its capacity and size to zero. This marks the arena as invalid for
|
||||||
* future allocation unless reinitialized.
|
* future allocation unless reinitialized.
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue