Compare commits

..
2 Commits
Author SHA1 Message Date
abdelrahman df03b48319 Update allocator interface
Release / release (push) Successful in 4s
2026-09-30 22:24:46 +01:00
abdelrahman cd93b2e479 Set minimum log length to 128
Release / release (push) Successful in 4s
2026-09-30 21:21:27 +01:00
9 changed files with 82 additions and 33 deletions
+16
View File
@@ -7,6 +7,22 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased] ## [Unreleased]
## [3.0.0] - 2026-09-30
### Added
- `temp_begin` and `temp_end` ops to the `WpAllocator` interface
### Removed
- `wpMemArenaAllocatorTempBegin` and `wpMemArenaAllocatorTempEnd`
## [2.6.0] - 2026-09-30
### Changed
- Minimum length for log messages from 32 to 128
## [2.5.0] - 2026-09-24 ## [2.5.0] - 2026-09-24
### Added ### Added
+1 -1
View File
@@ -1 +1 @@
2.5.0 3.0.0
+24
View File
@@ -56,6 +56,26 @@ void wpMemAllocatorFree(const WpAllocator *allocator, void **ptr, u64 size) {
allocator->free(ptr, size, allocator->obj); allocator->free(ptr, size, allocator->obj);
} }
void wpMemAllocatorTempBegin(const WpAllocator *allocator) {
wpDebugAssert(allocator != NULL, "`allocator` should not be NULL");
if (!wpMemAllocatorOpSupported(allocator, WP_MEM_OP_TEMP_BEGIN)) {
return;
}
allocator->temp_begin(allocator->obj);
}
void wpMemAllocatorTempEnd(const WpAllocator *allocator) {
wpDebugAssert(allocator != NULL, "`allocator` should not be NULL");
if (!wpMemAllocatorOpSupported(allocator, WP_MEM_OP_TEMP_END)) {
return;
}
allocator->temp_end(allocator->obj);
}
b8 wpMemAllocatorOpSupported(const WpAllocator *allocator, WpMemOp op) { b8 wpMemAllocatorOpSupported(const WpAllocator *allocator, WpMemOp op) {
wpDebugAssert(allocator != NULL, "`allocator` should not be NULL"); wpDebugAssert(allocator != NULL, "`allocator` should not be NULL");
@@ -70,6 +90,10 @@ b8 wpMemAllocatorOpSupported(const WpAllocator *allocator, WpMemOp op) {
return allocator->realloc_aligned != NULL; return allocator->realloc_aligned != NULL;
case WP_MEM_OP_FREE: case WP_MEM_OP_FREE:
return allocator->free != NULL; return allocator->free != NULL;
case WP_MEM_OP_TEMP_BEGIN:
return allocator->temp_begin != NULL;
case WP_MEM_OP_TEMP_END:
return allocator->temp_end != NULL;
default: default:
break; break;
} }
+8
View File
@@ -17,6 +17,8 @@ typedef enum WpMemOp {
WP_MEM_OP_REALLOC, WP_MEM_OP_REALLOC,
WP_MEM_OP_REALLOC_ALIGNED, WP_MEM_OP_REALLOC_ALIGNED,
WP_MEM_OP_FREE, WP_MEM_OP_FREE,
WP_MEM_OP_TEMP_BEGIN,
WP_MEM_OP_TEMP_END,
COUNT_MEM_OPS COUNT_MEM_OPS
} WpMemOp; } WpMemOp;
@@ -26,6 +28,8 @@ typedef void *(WpMemAllocAlignedFunc)(u64 size, u64 alignment, void *alloc_obj)
typedef void *(WpMemReallocFunc)(void *ptr, u64 old_size, u64 new_size, void *alloc_obj); typedef void *(WpMemReallocFunc)(void *ptr, u64 old_size, u64 new_size, void *alloc_obj);
typedef void *(WpMemReallocAlignedFunc)(void *ptr, u64 old_size, u64 new_size, u64 alignment, void *alloc_obj); typedef void *(WpMemReallocAlignedFunc)(void *ptr, u64 old_size, u64 new_size, u64 alignment, void *alloc_obj);
typedef void (WpMemFreeFunc)(void **ptr, u64 size, void *alloc_obj); typedef void (WpMemFreeFunc)(void **ptr, u64 size, void *alloc_obj);
typedef void (WpMemTempBeginFunc)(void *alloc_obj);
typedef void (WpMemTempEndFunc)(void *alloc_obj);
typedef struct WpAllocator WpAllocator; typedef struct WpAllocator WpAllocator;
struct WpAllocator { struct WpAllocator {
@@ -35,6 +39,8 @@ struct WpAllocator {
WpMemReallocFunc *realloc; WpMemReallocFunc *realloc;
WpMemReallocAlignedFunc *realloc_aligned; WpMemReallocAlignedFunc *realloc_aligned;
WpMemFreeFunc *free; WpMemFreeFunc *free;
WpMemTempBeginFunc *temp_begin;
WpMemTempEndFunc *temp_end;
}; };
#ifdef WP_PLATFORM_CPP #ifdef WP_PLATFORM_CPP
@@ -52,6 +58,8 @@ void *wpMemAllocatorRealloc(const WpAllocator *allocator, void *ptr, u64 old_siz
void *wpMemAllocatorReallocAligned(const WpAllocator *allocator, void *ptr, u64 old_size, void *wpMemAllocatorReallocAligned(const WpAllocator *allocator, void *ptr, u64 old_size,
u64 new_size, u64 alignment); u64 new_size, u64 alignment);
void wpMemAllocatorFree(const WpAllocator *allocator, void **ptr, u64 size); void wpMemAllocatorFree(const WpAllocator *allocator, void **ptr, u64 size);
void wpMemAllocatorTempBegin(const WpAllocator *allocator);
void wpMemAllocatorTempEnd(const WpAllocator *allocator);
b8 wpMemAllocatorOpSupported(const WpAllocator *allocator, WpMemOp op); b8 wpMemAllocatorOpSupported(const WpAllocator *allocator, WpMemOp op);
#ifdef WP_PLATFORM_CPP #ifdef WP_PLATFORM_CPP
+1 -1
View File
@@ -8,7 +8,7 @@
#include "../os/file/file.h" #include "../os/file/file.h"
#include <time.h> #include <time.h>
#define MIN_LOG_MSG_LENGTH 32 #define MIN_LOG_MSG_LENGTH 128
#define TIME_BUF_CAPACITY 70 #define TIME_BUF_CAPACITY 70
wp_intern WpStr8RO L_BRACKET = wpStr8LitRo("["); wp_intern WpStr8RO L_BRACKET = wpStr8LitRo("[");
+14 -11
View File
@@ -2,7 +2,6 @@
#include "mem_arena_allocator.h" #include "mem_arena_allocator.h"
#include "mem_arena.h" #include "mem_arena.h"
#include "../../mem/mem_os.h"
#include "../../../common/aliases/aliases.h" #include "../../../common/aliases/aliases.h"
#include "../../../common/assert/assert.h" #include "../../../common/assert/assert.h"
@@ -12,6 +11,8 @@ wp_intern void *memArenaAllocAligned(u64 size, u64 alignment, void *alloc_obj);
wp_intern void *memArenaRealloc(void *ptr, u64 old_size, u64 new_size, void *alloc_obj); wp_intern void *memArenaRealloc(void *ptr, u64 old_size, u64 new_size, void *alloc_obj);
wp_intern void *memArenaReallocAligned(void *ptr, u64 old_size, u64 new_size, u64 alignment, wp_intern void *memArenaReallocAligned(void *ptr, u64 old_size, u64 new_size, u64 alignment,
void *alloc_obj); void *alloc_obj);
wp_intern void memArenaTempBegin(void *alloc_obj);
wp_intern void memArenaTempEnd(void *alloc_obj);
WpAllocator wpMemArenaAllocatorInitWithBuffer(u8 *buffer, u64 buffer_size) { WpAllocator wpMemArenaAllocatorInitWithBuffer(u8 *buffer, u64 buffer_size) {
WpAllocator allocator = {0}; WpAllocator allocator = {0};
@@ -37,16 +38,6 @@ WpAllocator wpMemArenaAllocatorInitCustom(u64 base_capacity, WpMemAllocFlags fla
return allocator; return allocator;
} }
void wpMemArenaAllocatorTempBegin(const WpAllocator *allocator) {
wpDebugAssert(allocator != NULL, "`allocator` should not be NULL");
wpMemArenaTempBegin((WpArena *)(allocator->obj));
}
void wpMemArenaAllocatorTempEnd(const WpAllocator *allocator) {
wpDebugAssert(allocator != NULL, "`allocator` should not be NULL");
wpMemArenaTempEnd((WpArena *)(allocator->obj));
}
void wpMemArenaAllocatorClear(WpAllocator *allocator) { void wpMemArenaAllocatorClear(WpAllocator *allocator) {
wpDebugAssert(allocator != NULL, "`allocator` should not be NULL"); wpDebugAssert(allocator != NULL, "`allocator` should not be NULL");
wpMemArenaClear((WpArena *)(allocator->obj)); wpMemArenaClear((WpArena *)(allocator->obj));
@@ -63,6 +54,8 @@ wp_intern void initialiseArenaAllocator(WpAllocator *allocator) {
allocator->alloc_aligned = memArenaAllocAligned; allocator->alloc_aligned = memArenaAllocAligned;
allocator->realloc = memArenaRealloc; allocator->realloc = memArenaRealloc;
allocator->realloc_aligned = memArenaReallocAligned; allocator->realloc_aligned = memArenaReallocAligned;
allocator->temp_begin = memArenaTempBegin;
allocator->temp_end = memArenaTempEnd;
} }
wp_intern void *memArenaAlloc(u64 size, void *alloc_obj) { wp_intern void *memArenaAlloc(u64 size, void *alloc_obj) {
@@ -85,3 +78,13 @@ wp_intern void *memArenaReallocAligned(void *ptr, u64 old_size, u64 new_size, u6
WpArena *arena = (WpArena *)alloc_obj; WpArena *arena = (WpArena *)alloc_obj;
return wpMemArenaReallocAligned(arena, ptr, old_size, new_size, alignment); return wpMemArenaReallocAligned(arena, ptr, old_size, new_size, alignment);
} }
wp_intern void memArenaTempBegin(void *alloc_obj) {
WpArena *arena = (WpArena *)alloc_obj;
wpMemArenaTempBegin(arena);
}
wp_intern void memArenaTempEnd(void *alloc_obj) {
WpArena *arena = (WpArena *)alloc_obj;
wpMemArenaTempEnd(arena);
}
@@ -34,8 +34,6 @@ BEGIN_C_LINKAGE
*/ */
WpAllocator wpMemArenaAllocatorInitCustom(u64 base_capacity, WpMemAllocFlags flags, b8 zero_buffer); WpAllocator wpMemArenaAllocatorInitCustom(u64 base_capacity, WpMemAllocFlags flags, b8 zero_buffer);
WpAllocator wpMemArenaAllocatorInitWithBuffer(u8 *buffer, u64 buffer_size); WpAllocator wpMemArenaAllocatorInitWithBuffer(u8 *buffer, u64 buffer_size);
void wpMemArenaAllocatorTempBegin(const WpAllocator *allocator);
void wpMemArenaAllocatorTempEnd(const WpAllocator *allocator);
void wpMemArenaAllocatorClear(WpAllocator *allocator); void wpMemArenaAllocatorClear(WpAllocator *allocator);
void wpMemArenaAllocatorDestroy(WpAllocator *allocator); void wpMemArenaAllocatorDestroy(WpAllocator *allocator);
+2 -2
View File
@@ -45,7 +45,7 @@ WpTestFuncResult test_arena_allocator_temp_begin(void) {
i32 *num1 = (i32 *)wpMemAllocatorAlloc(&temp_allocator, sizeof(i32)); i32 *num1 = (i32 *)wpMemAllocatorAlloc(&temp_allocator, sizeof(i32));
b8 result = num1 != NULL; b8 result = num1 != NULL;
wpMemArenaAllocatorTempBegin(&temp_allocator); wpMemAllocatorTempBegin(&temp_allocator);
i32 *num2 = (i32 *)wpMemAllocatorAlloc(&temp_allocator, sizeof(i32)); i32 *num2 = (i32 *)wpMemAllocatorAlloc(&temp_allocator, sizeof(i32));
result = result && num2 != NULL; result = result && num2 != NULL;
i32 *num3 = (i32 *)wpMemAllocatorAlloc(&temp_allocator, sizeof(i32)); i32 *num3 = (i32 *)wpMemAllocatorAlloc(&temp_allocator, sizeof(i32));
@@ -55,7 +55,7 @@ WpTestFuncResult test_arena_allocator_temp_begin(void) {
} }
WpTestFuncResult test_arena_allocator_temp_end(void) { WpTestFuncResult test_arena_allocator_temp_end(void) {
wpMemArenaAllocatorTempEnd(&temp_allocator); wpMemAllocatorTempEnd(&temp_allocator);
i32 *num1 = (i32 *)wpMemAllocatorAlloc(&temp_allocator, sizeof(i32)); i32 *num1 = (i32 *)wpMemAllocatorAlloc(&temp_allocator, sizeof(i32));
b8 result = num1 != NULL; b8 result = num1 != NULL;
i32 *num2 = (i32 *)wpMemAllocatorAlloc(&temp_allocator, sizeof(i32)); i32 *num2 = (i32 *)wpMemAllocatorAlloc(&temp_allocator, sizeof(i32));
+2 -2
View File
@@ -45,7 +45,7 @@ WpTestFuncResult test_arena_allocator_temp_begin(void) {
i32 *num1 = (i32 *)wpMemAllocatorAlloc(&temp_allocator, sizeof(i32)); i32 *num1 = (i32 *)wpMemAllocatorAlloc(&temp_allocator, sizeof(i32));
b8 result = num1 != NULL; b8 result = num1 != NULL;
wpMemArenaAllocatorTempBegin(&temp_allocator); wpMemAllocatorTempBegin(&temp_allocator);
i32 *num2 = (i32 *)wpMemAllocatorAlloc(&temp_allocator, sizeof(i32)); i32 *num2 = (i32 *)wpMemAllocatorAlloc(&temp_allocator, sizeof(i32));
result = result && num2 != NULL; result = result && num2 != NULL;
i32 *num3 = (i32 *)wpMemAllocatorAlloc(&temp_allocator, sizeof(i32)); i32 *num3 = (i32 *)wpMemAllocatorAlloc(&temp_allocator, sizeof(i32));
@@ -55,7 +55,7 @@ WpTestFuncResult test_arena_allocator_temp_begin(void) {
} }
WpTestFuncResult test_arena_allocator_temp_end(void) { WpTestFuncResult test_arena_allocator_temp_end(void) {
wpMemArenaAllocatorTempEnd(&temp_allocator); wpMemAllocatorTempEnd(&temp_allocator);
i32 *num1 = (i32 *)wpMemAllocatorAlloc(&temp_allocator, sizeof(i32)); i32 *num1 = (i32 *)wpMemAllocatorAlloc(&temp_allocator, sizeof(i32));
b8 result = num1 != NULL; b8 result = num1 != NULL;
i32 *num2 = (i32 *)wpMemAllocatorAlloc(&temp_allocator, sizeof(i32)); i32 *num2 = (i32 *)wpMemAllocatorAlloc(&temp_allocator, sizeof(i32));