diff options
Diffstat (limited to 'src/memory.h')
-rw-r--r-- | src/memory.h | 97 |
1 files changed, 8 insertions, 89 deletions
diff --git a/src/memory.h b/src/memory.h index 80c60724..ace3abce 100644 --- a/src/memory.h +++ b/src/memory.h @@ -4,99 +4,18 @@ #ifndef SERD_SRC_MEMORY_H #define SERD_SRC_MEMORY_H -#include "serd/memory.h" #include "serd/world.h" +#include "zix/allocator.h" #include <stddef.h> #include <string.h> -// Allocator convenience wrappers that fall back to the default for NULL - -/// Convenience wrapper that defers to malloc() if allocator is null -static inline void* -serd_amalloc(SerdAllocator* const allocator, const size_t size) -{ - SerdAllocator* const actual = - allocator ? allocator : serd_default_allocator(); - - return actual->malloc(actual, size); -} - -/// Convenience wrapper that defers to calloc() if allocator is null -static inline void* -serd_acalloc(SerdAllocator* const allocator, - const size_t nmemb, - const size_t size) -{ - SerdAllocator* const actual = - allocator ? allocator : serd_default_allocator(); - - return actual->calloc(actual, nmemb, size); -} - -/// Convenience wrapper that defers to realloc() if allocator is null -static inline void* -serd_arealloc(SerdAllocator* const allocator, - void* const ptr, - const size_t size) -{ - SerdAllocator* const actual = - allocator ? allocator : serd_default_allocator(); - - return actual->realloc(actual, ptr, size); -} - -/// Convenience wrapper that defers to free() if allocator is null -static inline void -serd_afree(SerdAllocator* const allocator, void* const ptr) -{ - SerdAllocator* const actual = - allocator ? allocator : serd_default_allocator(); - - actual->free(actual, ptr); -} - -/// Convenience wrapper that defers to the system allocator if allocator is null -static inline void* -serd_aaligned_alloc(SerdAllocator* const allocator, - const size_t alignment, - const size_t size) -{ - SerdAllocator* const actual = - allocator ? allocator : serd_default_allocator(); - - return actual->aligned_alloc(actual, alignment, size); -} - -/// Convenience wrapper for serd_aaligned_alloc that zeros memory -static inline void* -serd_aaligned_calloc(SerdAllocator* const allocator, - const size_t alignment, - const size_t size) -{ - void* const ptr = serd_aaligned_alloc(allocator, alignment, size); - if (ptr) { - memset(ptr, 0, size); - } - return ptr; -} - -/// Convenience wrapper that defers to the system allocator if allocator is null -static inline void -serd_aaligned_free(SerdAllocator* const allocator, void* const ptr) -{ - SerdAllocator* const actual = - allocator ? allocator : serd_default_allocator(); - - actual->aligned_free(actual, ptr); -} - -// World convenience wrappers +// Allocator convenience wrappers that use the world allocator static inline void* serd_wmalloc(const SerdWorld* const world, const size_t size) { - return serd_amalloc(serd_world_allocator(world), size); + return zix_malloc(serd_world_allocator(world), size); } static inline void* @@ -104,19 +23,19 @@ serd_wcalloc(const SerdWorld* const world, const size_t nmemb, const size_t size) { - return serd_acalloc(serd_world_allocator(world), nmemb, size); + return zix_calloc(serd_world_allocator(world), nmemb, size); } static inline void* serd_wrealloc(const SerdWorld* const world, void* const ptr, const size_t size) { - return serd_arealloc(serd_world_allocator(world), ptr, size); + return zix_realloc(serd_world_allocator(world), ptr, size); } static inline void serd_wfree(const SerdWorld* const world, void* const ptr) { - serd_afree(serd_world_allocator(world), ptr); + zix_free(serd_world_allocator(world), ptr); } static inline void* @@ -124,13 +43,13 @@ serd_waligned_alloc(const SerdWorld* const world, const size_t alignment, const size_t size) { - return serd_aaligned_alloc(serd_world_allocator(world), alignment, size); + return zix_aligned_alloc(serd_world_allocator(world), alignment, size); } static inline void serd_waligned_free(const SerdWorld* const world, void* const ptr) { - serd_aaligned_free(serd_world_allocator(world), ptr); + zix_aligned_free(serd_world_allocator(world), ptr); } #endif // SERD_SRC_MEMORY_H |