Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3d6755d4d4 | ||
|
|
ae7a0806df | ||
|
|
1a00f82823 |
No files matched your search
@@ -7,6 +7,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
|
||||||
|
## [3.6.1] - 2026-11-23
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- Arena initialisation checks
|
||||||
|
|
||||||
|
## [3.6.0] - 2026-11-22
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- Functionality to query memory allocator usage
|
||||||
|
|
||||||
## [3.5.0] - 2026-11-16
|
## [3.5.0] - 2026-11-16
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|||||||
@@ -76,6 +76,16 @@ void wpMemAllocatorTempEnd(const WpAllocator *allocator) {
|
|||||||
allocator->temp_end(allocator->obj);
|
allocator->temp_end(allocator->obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
WpAllocatorUsage wpMemAllocatorQueryUsage(const WpAllocator *allocator) {
|
||||||
|
wpDebugAssert(allocator != NULL, "`allocator` should not be NULL");
|
||||||
|
|
||||||
|
if (!wpMemAllocatorOpSupported(allocator, WP_MEM_OP_QUERY_USAGE)) {
|
||||||
|
return (WpAllocatorUsage){0};
|
||||||
|
}
|
||||||
|
|
||||||
|
return allocator->query_usage(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");
|
||||||
|
|
||||||
@@ -94,6 +104,8 @@ b8 wpMemAllocatorOpSupported(const WpAllocator *allocator, WpMemOp op) {
|
|||||||
return allocator->temp_begin != NULL;
|
return allocator->temp_begin != NULL;
|
||||||
case WP_MEM_OP_TEMP_END:
|
case WP_MEM_OP_TEMP_END:
|
||||||
return allocator->temp_end != NULL;
|
return allocator->temp_end != NULL;
|
||||||
|
case WP_MEM_OP_QUERY_USAGE:
|
||||||
|
return allocator->query_usage != NULL;
|
||||||
case COUNT_MEM_OPS:
|
case COUNT_MEM_OPS:
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -19,10 +19,16 @@ typedef enum WpMemOp {
|
|||||||
WP_MEM_OP_FREE,
|
WP_MEM_OP_FREE,
|
||||||
WP_MEM_OP_TEMP_BEGIN,
|
WP_MEM_OP_TEMP_BEGIN,
|
||||||
WP_MEM_OP_TEMP_END,
|
WP_MEM_OP_TEMP_END,
|
||||||
|
WP_MEM_OP_QUERY_USAGE,
|
||||||
|
|
||||||
COUNT_MEM_OPS
|
COUNT_MEM_OPS
|
||||||
} WpMemOp;
|
} WpMemOp;
|
||||||
|
|
||||||
|
typedef struct WpAllocatorUsage {
|
||||||
|
u64 capacity;
|
||||||
|
u64 used;
|
||||||
|
} WpAllocatorUsage;
|
||||||
|
|
||||||
typedef void *(WpMemAllocFunc)(u64 size, void *alloc_obj);
|
typedef void *(WpMemAllocFunc)(u64 size, void *alloc_obj);
|
||||||
typedef void *(WpMemAllocAlignedFunc)(u64 size, u64 alignment, void *alloc_obj);
|
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);
|
||||||
@@ -30,9 +36,9 @@ typedef void *(WpMemReallocAlignedFunc)(void *ptr, u64 old_size, u64 new_size, u
|
|||||||
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 (WpMemTempBeginFunc)(void *alloc_obj);
|
||||||
typedef void (WpMemTempEndFunc)(void *alloc_obj);
|
typedef void (WpMemTempEndFunc)(void *alloc_obj);
|
||||||
|
typedef WpAllocatorUsage (WpMemQueryUsageFunc)(void *alloc_obj);
|
||||||
|
|
||||||
typedef struct WpAllocator WpAllocator;
|
typedef struct WpAllocator {
|
||||||
struct WpAllocator {
|
|
||||||
void *obj;
|
void *obj;
|
||||||
WpMemAllocFunc *alloc;
|
WpMemAllocFunc *alloc;
|
||||||
WpMemAllocAlignedFunc *alloc_aligned;
|
WpMemAllocAlignedFunc *alloc_aligned;
|
||||||
@@ -41,7 +47,8 @@ struct WpAllocator {
|
|||||||
WpMemFreeFunc *free;
|
WpMemFreeFunc *free;
|
||||||
WpMemTempBeginFunc *temp_begin;
|
WpMemTempBeginFunc *temp_begin;
|
||||||
WpMemTempEndFunc *temp_end;
|
WpMemTempEndFunc *temp_end;
|
||||||
};
|
WpMemQueryUsageFunc *query_usage;
|
||||||
|
} WpAllocator;
|
||||||
|
|
||||||
#ifdef WP_PLATFORM_CPP
|
#ifdef WP_PLATFORM_CPP
|
||||||
#define wpMemAllocatorInvalid(ALLOCATOR) ([&]() { \
|
#define wpMemAllocatorInvalid(ALLOCATOR) ([&]() { \
|
||||||
@@ -60,6 +67,7 @@ void *wpMemAllocatorReallocAligned(const WpAllocator *allocator, void *ptr, u64
|
|||||||
void wpMemAllocatorFree(const WpAllocator *allocator, void **ptr, u64 size);
|
void wpMemAllocatorFree(const WpAllocator *allocator, void **ptr, u64 size);
|
||||||
void wpMemAllocatorTempBegin(const WpAllocator *allocator);
|
void wpMemAllocatorTempBegin(const WpAllocator *allocator);
|
||||||
void wpMemAllocatorTempEnd(const WpAllocator *allocator);
|
void wpMemAllocatorTempEnd(const WpAllocator *allocator);
|
||||||
|
WpAllocatorUsage wpMemAllocatorQueryUsage(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
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ struct WpArena {
|
|||||||
};
|
};
|
||||||
|
|
||||||
b8 wpMemArenaInitBuffer(WpArena **arena, u8 *buffer, u64 buffer_size) {
|
b8 wpMemArenaInitBuffer(WpArena **arena, u8 *buffer, u64 buffer_size) {
|
||||||
if (!arena || *arena || buffer_size < sizeof(WpArena)) {
|
if (arena == NULL || *arena != NULL || buffer_size < sizeof(WpArena)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -51,7 +51,7 @@ b8 wpMemArenaInitBuffer(WpArena **arena, u8 *buffer, u64 buffer_size) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
b8 wpMemArenaInitAllocatedCustom(WpArena **arena, u64 base_capacity, WpMemAllocFlags flags, b8 zero_buffer) {
|
b8 wpMemArenaInitAllocatedCustom(WpArena **arena, u64 base_capacity, WpMemAllocFlags flags, b8 zero_buffer) {
|
||||||
if (!arena || *arena || base_capacity == 0) {
|
if (arena == NULL || *arena != NULL || base_capacity == 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -59,7 +59,7 @@ b8 wpMemArenaInitAllocatedCustom(WpArena **arena, u64 base_capacity, WpMemAllocF
|
|||||||
u64 alloc_size = wpMiscUtilsU64RoundUpPow2(size);
|
u64 alloc_size = wpMiscUtilsU64RoundUpPow2(size);
|
||||||
u8 *allocated = (u8 *)wpOsMemAlloc(NULL, alloc_size, WP_MEM_ACCESS_READ_WRITE, flags,
|
u8 *allocated = (u8 *)wpOsMemAlloc(NULL, alloc_size, WP_MEM_ACCESS_READ_WRITE, flags,
|
||||||
zero_buffer ? WP_MEM_INIT_INITIALISED : WP_MEM_INIT_UNINITIALISED);
|
zero_buffer ? WP_MEM_INIT_INITIALISED : WP_MEM_INIT_UNINITIALISED);
|
||||||
if (!allocated) {
|
if (allocated == NULL) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -172,6 +172,15 @@ void wpMemArenaTempEnd(WpArena *arena) {
|
|||||||
arena->prev_offset = NULL;
|
arena->prev_offset = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
WpAllocatorUsage wpMemArenaQueryUsage(WpArena *arena) {
|
||||||
|
wpDebugAssert(arena != NULL, "`arena` should not be NULL");
|
||||||
|
|
||||||
|
return (WpAllocatorUsage){
|
||||||
|
.capacity = arena->capacity,
|
||||||
|
.used = arena->offset - arena->buf,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
void wpMemArenaClear(WpArena *arena) {
|
void wpMemArenaClear(WpArena *arena) {
|
||||||
wpDebugAssert(arena != NULL, "`arena` should not be NULL");
|
wpDebugAssert(arena != NULL, "`arena` should not be NULL");
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
#include "../../mem/mem_os.h"
|
#include "../../mem/mem_os.h"
|
||||||
#include "../../../common/aliases/aliases.h"
|
#include "../../../common/aliases/aliases.h"
|
||||||
#include "../../../common/platform/platform.h"
|
#include "../../../common/platform/platform.h"
|
||||||
|
#include "../../../base/mem/allocator/mem_allocator.h"
|
||||||
|
|
||||||
#ifdef WP_PLATFORM_CPP
|
#ifdef WP_PLATFORM_CPP
|
||||||
BEGIN_C_LINKAGE
|
BEGIN_C_LINKAGE
|
||||||
@@ -35,6 +36,7 @@ void *wpMemArenaRealloc(WpArena *arena, void *ptr, u64 old_size, u64 new_size);
|
|||||||
void *wpMemArenaReallocAligned(WpArena *arena, void *ptr, u64 old_size, u64 new_size, u64 alignment);
|
void *wpMemArenaReallocAligned(WpArena *arena, void *ptr, u64 old_size, u64 new_size, u64 alignment);
|
||||||
void wpMemArenaTempBegin(WpArena *arena);
|
void wpMemArenaTempBegin(WpArena *arena);
|
||||||
void wpMemArenaTempEnd(WpArena *arena);
|
void wpMemArenaTempEnd(WpArena *arena);
|
||||||
|
WpAllocatorUsage wpMemArenaQueryUsage(WpArena *arena);
|
||||||
void wpMemArenaClear(WpArena *arena);
|
void wpMemArenaClear(WpArena *arena);
|
||||||
void wpMemArenaDestroy(WpArena **arena);
|
void wpMemArenaDestroy(WpArena **arena);
|
||||||
|
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ wp_intern void *memArenaReallocAligned(void *ptr, u64 old_size, u64 new_size, u6
|
|||||||
void *alloc_obj);
|
void *alloc_obj);
|
||||||
wp_intern void memArenaTempBegin(void *alloc_obj);
|
wp_intern void memArenaTempBegin(void *alloc_obj);
|
||||||
wp_intern void memArenaTempEnd(void *alloc_obj);
|
wp_intern void memArenaTempEnd(void *alloc_obj);
|
||||||
|
wp_intern WpAllocatorUsage memArenaQueryUsage(void *alloc_obj);
|
||||||
|
|
||||||
WpAllocator wpMemArenaAllocatorInitWithBuffer(u8 *buffer, u64 buffer_size) {
|
WpAllocator wpMemArenaAllocatorInitWithBuffer(u8 *buffer, u64 buffer_size) {
|
||||||
WpAllocator allocator = {0};
|
WpAllocator allocator = {0};
|
||||||
@@ -56,6 +57,7 @@ wp_intern void initialiseArenaAllocator(WpAllocator *allocator) {
|
|||||||
allocator->realloc_aligned = memArenaReallocAligned;
|
allocator->realloc_aligned = memArenaReallocAligned;
|
||||||
allocator->temp_begin = memArenaTempBegin;
|
allocator->temp_begin = memArenaTempBegin;
|
||||||
allocator->temp_end = memArenaTempEnd;
|
allocator->temp_end = memArenaTempEnd;
|
||||||
|
allocator->query_usage = memArenaQueryUsage;
|
||||||
}
|
}
|
||||||
|
|
||||||
wp_intern void *memArenaAlloc(u64 size, void *alloc_obj) {
|
wp_intern void *memArenaAlloc(u64 size, void *alloc_obj) {
|
||||||
@@ -88,3 +90,8 @@ wp_intern void memArenaTempEnd(void *alloc_obj) {
|
|||||||
WpArena *arena = (WpArena *)alloc_obj;
|
WpArena *arena = (WpArena *)alloc_obj;
|
||||||
wpMemArenaTempEnd(arena);
|
wpMemArenaTempEnd(arena);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wp_intern WpAllocatorUsage memArenaQueryUsage(void *alloc_obj) {
|
||||||
|
WpArena *arena = (WpArena *)alloc_obj;
|
||||||
|
return wpMemArenaQueryUsage(arena);
|
||||||
|
}
|
||||||
+2
-4
@@ -51,8 +51,7 @@ u64 wpFileRead(void *dst_buf, WpFile *file, u64 byte_count) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
i64 wpFileWrite(const void *src_buf, WpFile *file, u64 byte_count) {
|
i64 wpFileWrite(const void *src_buf, WpFile *file, u64 byte_count) {
|
||||||
wpDebugAssert(src_buf != NULL && file != NULL,
|
wpDebugAssert(src_buf != NULL && file != NULL, "`src_buf` and `file` should not be NULL.");
|
||||||
"`src_buf` and `file` should not be NULL.");
|
|
||||||
return fileWrite(src_buf, file, byte_count);
|
return fileWrite(src_buf, file, byte_count);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -67,8 +66,7 @@ i64 wpFileWriteStr8(WpStr8RO *str, WpFile *file) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
u64 wpFileReadArray(WpArray dst_buf, WpFile *file, u64 item_count) {
|
u64 wpFileReadArray(WpArray dst_buf, WpFile *file, u64 item_count) {
|
||||||
wpDebugAssert(dst_buf != NULL && file != NULL,
|
wpDebugAssert(dst_buf != NULL && file != NULL, "`dst_buf` and `file` should not be NULL.");
|
||||||
"`dst_buf` and `file` should not be NULL.");
|
|
||||||
|
|
||||||
i64 _file_length = wpFileGetLength(file);
|
i64 _file_length = wpFileGetLength(file);
|
||||||
if (_file_length < 0) {
|
if (_file_length < 0) {
|
||||||
|
|||||||
Reference in new issue
Block a user