Rename mem allocator

This commit is contained in:
2026-06-26 16:24:03 +01:00
parent 99d6404ec4
commit f4bffec947
31 changed files with 167 additions and 167 deletions
+11 -11
View File
@@ -6,15 +6,15 @@
#include "../../../common/aliases/aliases.h"
#include "../../../common/assert/assert.h"
wp_intern void initialise_arena_allocator(Allocator *allocator);
wp_intern void initialise_arena_allocator(WpAllocator *allocator);
wp_intern void *mem_arena_alloc(u64 size, void *alloc_obj);
wp_intern void *mem_arena_alloc_aligned(u64 size, u64 alignment, void *alloc_obj);
wp_intern void *mem_arena_realloc(void *ptr, u64 old_size, u64 new_size, void *alloc_obj);
wp_intern void *mem_arena_realloc_aligned(void *ptr, u64 old_size, u64 new_size, u64 alignment,
void *alloc_obj);
Allocator wapp_mem_arena_allocator_init_with_buffer(u8 *buffer, u64 buffer_size) {
Allocator allocator = {0};
WpAllocator wapp_mem_arena_allocator_init_with_buffer(u8 *buffer, u64 buffer_size) {
WpAllocator allocator = {0};
b8 initialised = wapp_mem_arena_init_buffer((Arena **)(&allocator.obj), buffer, buffer_size);
if (!initialised) {
return allocator;
@@ -25,8 +25,8 @@ Allocator wapp_mem_arena_allocator_init_with_buffer(u8 *buffer, u64 buffer_size)
return allocator;
}
Allocator wapp_mem_arena_allocator_init_custom(u64 base_capacity, MemAllocFlags flags, b8 zero_buffer) {
Allocator allocator = {0};
WpAllocator wapp_mem_arena_allocator_init_custom(u64 base_capacity, MemAllocFlags flags, b8 zero_buffer) {
WpAllocator allocator = {0};
b8 initialised = wapp_mem_arena_init_allocated_custom((Arena **)(&allocator.obj), base_capacity, flags, zero_buffer);
if (!initialised) {
return allocator;
@@ -37,28 +37,28 @@ Allocator wapp_mem_arena_allocator_init_custom(u64 base_capacity, MemAllocFlags
return allocator;
}
void wapp_mem_arena_allocator_temp_begin(const Allocator *allocator) {
void wapp_mem_arena_allocator_temp_begin(const WpAllocator *allocator) {
wpDebugAssert(allocator != NULL, "`allocator` should not be NULL");
wapp_mem_arena_temp_begin((Arena *)(allocator->obj));
}
void wapp_mem_arena_allocator_temp_end(const Allocator *allocator) {
void wapp_mem_arena_allocator_temp_end(const WpAllocator *allocator) {
wpDebugAssert(allocator != NULL, "`allocator` should not be NULL");
wapp_mem_arena_temp_end((Arena *)(allocator->obj));
}
void wapp_mem_arena_allocator_clear(Allocator *allocator) {
void wapp_mem_arena_allocator_clear(WpAllocator *allocator) {
wpDebugAssert(allocator != NULL, "`allocator` should not be NULL");
wapp_mem_arena_clear((Arena *)(allocator->obj));
}
void wapp_mem_arena_allocator_destroy(Allocator *allocator) {
void wapp_mem_arena_allocator_destroy(WpAllocator *allocator) {
wpDebugAssert(allocator != NULL, "`allocator` should not be NULL");
wapp_mem_arena_destroy((Arena **)(&(allocator->obj)));
*allocator = (Allocator){0};
*allocator = (WpAllocator){0};
}
wp_intern void initialise_arena_allocator(Allocator *allocator) {
wp_intern void initialise_arena_allocator(WpAllocator *allocator) {
allocator->alloc = mem_arena_alloc;
allocator->alloc_aligned = mem_arena_alloc_aligned;
allocator->realloc = mem_arena_realloc;
@@ -22,9 +22,9 @@ BEGIN_C_LINKAGE
(wapp_mem_arena_allocator_init_custom(base_capacity, WAPP_MEM_ALLOC_RESERVE | WAPP_MEM_ALLOC_COMMIT, true))
/**
* Wraps an Arena in an Allocator object. It attempts to initialise the Arena
* Wraps an Arena in an WpAllocator object. It attempts to initialise the Arena
* and, if successful, defines the operations supported by it to be used by the
* Allocator.
* WpAllocator.
*
* An Arena allocator only supports normal allocation and aligned allocation.
* Reallocation, aligned reallocation and freeing aren't implemented.
@@ -32,12 +32,12 @@ BEGIN_C_LINKAGE
* The `wapp_mem_arena_allocator_init_custom` provides the most control over how
* the Arena is initialised. Wrapper macros are provided for easier use.
*/
Allocator wapp_mem_arena_allocator_init_custom(u64 base_capacity, MemAllocFlags flags, b8 zero_buffer);
Allocator wapp_mem_arena_allocator_init_with_buffer(u8 *buffer, u64 buffer_size);
void wapp_mem_arena_allocator_temp_begin(const Allocator *allocator);
void wapp_mem_arena_allocator_temp_end(const Allocator *allocator);
void wapp_mem_arena_allocator_clear(Allocator *allocator);
void wapp_mem_arena_allocator_destroy(Allocator *allocator);
WpAllocator wapp_mem_arena_allocator_init_custom(u64 base_capacity, MemAllocFlags flags, b8 zero_buffer);
WpAllocator wapp_mem_arena_allocator_init_with_buffer(u8 *buffer, u64 buffer_size);
void wapp_mem_arena_allocator_temp_begin(const WpAllocator *allocator);
void wapp_mem_arena_allocator_temp_end(const WpAllocator *allocator);
void wapp_mem_arena_allocator_clear(WpAllocator *allocator);
void wapp_mem_arena_allocator_destroy(WpAllocator *allocator);
#ifdef WP_PLATFORM_CPP
END_C_LINKAGE
+3 -3
View File
@@ -63,7 +63,7 @@ CPATH_JOIN_LOOP_END:
return CPATH_JOIN_SUCCESS;
}
WpStr8 *dirup(const Allocator *allocator, WpStr8RO *path, u64 levels) {
WpStr8 *dirup(const WpAllocator *allocator, WpStr8RO *path, u64 levels) {
WpStr8 *output = NULL;
if (!allocator || !path) {
goto RETURN_DIRUP;
@@ -88,8 +88,8 @@ WpStr8 *dirup(const Allocator *allocator, WpStr8RO *path, u64 levels) {
goto RETURN_DIRUP;
}
Allocator tmp_arena = wapp_mem_arena_allocator_init(MiB(8));
if (wapp_mem_allocator_invalid(&tmp_arena)) {
WpAllocator tmp_arena = wapp_mem_arena_allocator_init(MiB(8));
if (wpMemAllocatorInvalid(&tmp_arena)) {
goto RETURN_DIRUP;
}
+1 -1
View File
@@ -36,7 +36,7 @@ enum {
};
u32 wapp_cpath_join_path(WpStr8 *dst, const WpStr8List *parts);
WpStr8 *dirup(const Allocator *allocator, WpStr8RO *path, u64 levels);
WpStr8 *dirup(const WpAllocator *allocator, WpStr8RO *path, u64 levels);
#ifdef WP_PLATFORM_CPP
END_C_LINKAGE
+1 -1
View File
@@ -7,7 +7,7 @@
#include "../../base/array/array.h"
#include "../../base/strings/str8/str8.h"
WFile *wapp_file_open(const Allocator *allocator, WpStr8RO *filepath, FileAccessMode mode) {
WFile *wapp_file_open(const WpAllocator *allocator, WpStr8RO *filepath, FileAccessMode mode) {
wpDebugAssert(allocator != NULL && filepath != NULL, "`allocator` and `filepath` should not be NULL");
wpDebugAssert(filepath->size < WAPP_PATH_MAX, "`filepath` exceeds max path limit.");
return _file_open(allocator, filepath, mode);
+2 -2
View File
@@ -46,7 +46,7 @@ wp_extern WFile *wapp_file_stdout(void);
// wapp_file_stderr to get the standard error stream
wp_extern WFile *wapp_file_stderr(void);
WFile *wapp_file_open(const Allocator *allocator, WpStr8RO *filepath, FileAccessMode mode);
WFile *wapp_file_open(const WpAllocator *allocator, WpStr8RO *filepath, FileAccessMode mode);
i64 wapp_file_get_current_position(WFile *file);
i64 wapp_file_seek(WFile *file, i64 offset, FileSeekOrigin origin);
i64 wapp_file_get_length(WFile *file);
@@ -61,7 +61,7 @@ i32 wapp_file_close(WFile *file);
i32 wapp_file_rename(WpStr8RO *old_filepath, WpStr8RO *new_filepath);
i32 wapp_file_remove(WpStr8RO *filepath);
wp_extern WFile *_file_open(const Allocator *allocator, WpStr8RO *filepath, FileAccessMode mode);
wp_extern WFile *_file_open(const WpAllocator *allocator, WpStr8RO *filepath, FileAccessMode mode);
wp_extern i64 _file_seek(WFile *file, i64 offset, FileSeekOrigin origin);
wp_extern u64 _file_read(void *dst_buf, u64 byte_count, WFile *file, u64 file_length);
wp_extern i64 _file_write(const void *src_buf, WFile *file, u64 byte_count);
+2 -2
View File
@@ -64,7 +64,7 @@ WFile *wapp_file_stderr(void) {
return &_stderr;
}
WFile *_file_open(const Allocator *allocator, WpStr8RO *filepath, FileAccessMode mode) {
WFile *_file_open(const WpAllocator *allocator, WpStr8RO *filepath, FileAccessMode mode) {
wp_persist c8 tmp[WAPP_PATH_MAX] = {0};
memset(tmp, 0, WAPP_PATH_MAX);
memcpy(tmp, filepath->buf, filepath->size);
@@ -74,7 +74,7 @@ WFile *_file_open(const Allocator *allocator, WpStr8RO *filepath, FileAccessMode
return NULL;
}
WFile *output = wapp_mem_allocator_alloc(allocator, sizeof(WFile));
WFile *output = wpMemAllocatorAlloc(allocator, sizeof(WFile));
if (output) {
output->fd = fd;
}
+2 -2
View File
@@ -72,7 +72,7 @@ WFile *wapp_file_stderr(void) {
return &_stderr;
}
WFile *_file_open(const Allocator *allocator, WpStr8RO *filepath, FileAccessMode mode) {
WFile *_file_open(const WpAllocator *allocator, WpStr8RO *filepath, FileAccessMode mode) {
wp_persist c8 tmp[WAPP_PATH_MAX] = {0};
memset(tmp, 0, WAPP_PATH_MAX);
memcpy(tmp, filepath->buf, filepath->size);
@@ -88,7 +88,7 @@ WFile *_file_open(const Allocator *allocator, WpStr8RO *filepath, FileAccessMode
return NULL;
}
WFile *output = wapp_mem_allocator_alloc(allocator, sizeof(WFile));
WFile *output = wpMemAllocatorAlloc(allocator, sizeof(WFile));
if (output) {
output->fh = fh;
}
+1 -1
View File
@@ -25,7 +25,7 @@ CMDResult wapp_shell_commander_execute(CMDOutHandling out_handling, WpStr8 *out_
return CMD_NO_EXIT(SHELL_ERR_INVALID_ARGS);
}
Allocator arena = wapp_mem_arena_allocator_init(KiB(500));
WpAllocator arena = wapp_mem_arena_allocator_init(KiB(500));
WpStr8 *cmd_str = wpStr8Join(&arena, cmd, &wpStr8LitRo(" "));
if (!cmd_str) {