Compare commits
26
Commits
v2.1.0
..
97de0b3eaa
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
97de0b3eaa | ||
|
|
0742c86f1d | ||
|
|
ecba164dd7 | ||
|
|
44c9e20235 | ||
|
|
1fc93fac24 | ||
|
|
e3856cf584 | ||
|
|
c832d5366e | ||
|
|
c29466b863 | ||
|
|
273dbf4535 | ||
|
|
f0e9da26bd | ||
|
|
1a0a5b5192 | ||
|
|
c0d83b5c3f | ||
|
|
c4134c4017 | ||
|
|
b802aba954 | ||
|
|
f4bffec947 | ||
|
|
99d6404ec4 | ||
|
|
e2b57d4aba | ||
|
|
acbfc9088c | ||
|
|
cd797683d2 | ||
|
|
28f95b1d41 | ||
|
|
cdca775681 | ||
|
|
e4c1068281 | ||
|
|
f679017fa7 | ||
|
|
65d99db738 | ||
|
|
61c1ec99e5 | ||
|
|
dc348f3e71 |
@@ -7,72 +7,29 @@
|
||||
|
||||
void *wpMemAllocatorAlloc(const WpAllocator *allocator, u64 size) {
|
||||
wpDebugAssert(allocator != NULL && (allocator->alloc) != NULL, "`allocator` and `allocator->alloc` should not be NULL");
|
||||
|
||||
if (wpMemAllocatorOpSupported(allocator, WP_MEM_OP_ALLOC)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return allocator->alloc(size, allocator->obj);
|
||||
}
|
||||
|
||||
void *wpMemAllocatorAllocAligned(const WpAllocator *allocator, u64 size, u64 alignment) {
|
||||
wpDebugAssert(allocator != NULL && (allocator->alloc_aligned) != NULL, "`allocator` and `allocator->alloc_aligned` should not be NULL");
|
||||
|
||||
if (wpMemAllocatorOpSupported(allocator, WP_MEM_OP_ALLOC_ALIGNED)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return allocator->alloc_aligned(size, alignment, allocator->obj);
|
||||
}
|
||||
|
||||
void *wpMemAllocatorRealloc(const WpAllocator *allocator, void *ptr, u64 old_size, u64 new_size) {
|
||||
wpDebugAssert(allocator != NULL && (allocator->realloc) != NULL, "`allocator` and `allocator->realloc` should not be NULL");
|
||||
|
||||
if (wpMemAllocatorOpSupported(allocator, WP_MEM_OP_REALLOC)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return allocator->realloc(ptr, old_size, new_size, allocator->obj);
|
||||
}
|
||||
|
||||
void *wpMemAllocatorReallocAligned(const WpAllocator *allocator, void *ptr, u64 old_size,
|
||||
u64 new_size, u64 alignment) {
|
||||
wpDebugAssert(allocator != NULL && (allocator->realloc_aligned) != NULL, "`allocator` and `allocator->realloc_aligned` should not be NULL");
|
||||
|
||||
if (wpMemAllocatorOpSupported(allocator, WP_MEM_OP_REALLOC_ALIGNED)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return allocator->realloc_aligned(ptr, old_size, new_size, alignment, allocator->obj);
|
||||
}
|
||||
|
||||
void wpMemAllocatorFree(const WpAllocator *allocator, void **ptr, u64 size) {
|
||||
wpDebugAssert(allocator != NULL && (allocator->free) != NULL, "`allocator` and `allocator->free` should not be NULL");
|
||||
|
||||
if (wpMemAllocatorOpSupported(allocator, WP_MEM_OP_FREE)) {
|
||||
if (!allocator || !(allocator->free)) {
|
||||
return;
|
||||
}
|
||||
|
||||
allocator->free(ptr, size, allocator->obj);
|
||||
}
|
||||
|
||||
b8 wpMemAllocatorOpSupported(const WpAllocator *allocator, WpMemOp op) {
|
||||
wpDebugAssert(allocator != NULL, "`allocator` should not be NULL");
|
||||
|
||||
switch (op) {
|
||||
case WP_MEM_OP_ALLOC:
|
||||
return allocator->alloc != NULL;
|
||||
case WP_MEM_OP_ALLOC_ALIGNED:
|
||||
return allocator->alloc_aligned != NULL;
|
||||
case WP_MEM_OP_REALLOC:
|
||||
return allocator->realloc != NULL;
|
||||
case WP_MEM_OP_REALLOC_ALIGNED:
|
||||
return allocator->realloc_aligned != NULL;
|
||||
case WP_MEM_OP_FREE:
|
||||
return allocator->free != NULL;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -11,16 +11,6 @@
|
||||
BEGIN_C_LINKAGE
|
||||
#endif // !WP_PLATFORM_CPP
|
||||
|
||||
typedef enum {
|
||||
WP_MEM_OP_ALLOC,
|
||||
WP_MEM_OP_ALLOC_ALIGNED,
|
||||
WP_MEM_OP_REALLOC,
|
||||
WP_MEM_OP_REALLOC_ALIGNED,
|
||||
WP_MEM_OP_FREE,
|
||||
|
||||
COUNT_MEM_OPS
|
||||
} WpMemOp;
|
||||
|
||||
typedef void *(WpMemAllocFunc)(u64 size, 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);
|
||||
@@ -52,7 +42,6 @@ void *wpMemAllocatorRealloc(const WpAllocator *allocator, void *ptr, u64 old_siz
|
||||
void *wpMemAllocatorReallocAligned(const WpAllocator *allocator, void *ptr, u64 old_size,
|
||||
u64 new_size, u64 alignment);
|
||||
void wpMemAllocatorFree(const WpAllocator *allocator, void **ptr, u64 size);
|
||||
b8 wpMemAllocatorOpSupported(const WpAllocator *allocator, WpMemOp op);
|
||||
|
||||
#ifdef WP_PLATFORM_CPP
|
||||
END_C_LINKAGE
|
||||
|
||||
Reference in New Issue
Block a user