diff options
| author | 2024-11-03 16:37:33 -0500 | |
|---|---|---|
| committer | 2024-11-03 16:37:33 -0500 | |
| commit | 90acc831f543182dfc78363a2a9c0ab3fec274d4 (patch) | |
| tree | c83d32b25be720ed53797654725c6a802d67eb22 /src | |
| parent | a8bd86763e3db5c4320bfaf6684a803026213968 (diff) | |
| download | libalabaster-90acc831f543182dfc78363a2a9c0ab3fec274d4.tar.gz libalabaster-90acc831f543182dfc78363a2a9c0ab3fec274d4.tar.bz2 libalabaster-90acc831f543182dfc78363a2a9c0ab3fec274d4.zip | |
lib: Cleanup no memory tracking case
Signed-off-by: Andrew Opalach <andrew@akon.city>
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib.c | 25 |
1 files changed, 2 insertions, 23 deletions
@@ -7,6 +7,7 @@ AL_ASSERT_TYPE_SIZE(int, 4); AL_ASSERT_TYPE_SIZE(unsigned, 4); +#ifdef AL_MEMORY_TRACKING #ifdef AL_USE_STDLIB static void *(*_al_malloc)(size_t) = malloc; static void *(*_al_calloc)(size_t, size_t) = calloc; @@ -17,8 +18,6 @@ s32 (*_al_posix_memalign)(void **, size_t, size_t) = posix_memalign; #endif // Testing allocation tracking stuff (Very scuffed, not thread-safe!). -//#define AL_MEMORY_TRACKING -#ifdef AL_MEMORY_TRACKING struct alloc_t { void *ptr; size_t size; @@ -37,26 +36,20 @@ static array(struct alloc_t) allocations; static u32 currently_allocated = 0; static u32 peak_allocated = 0; static u32 total_allocated = 0; -#endif void al_malloc_init(void) { -#ifdef AL_MEMORY_TRACKING al_array_init(allocations); -#endif } void al_malloc_close(void) { -#ifdef AL_MEMORY_TRACKING al_array_free(allocations); -#endif } void *al_malloc(size_t n) { void *ptr = _al_malloc(n); -#ifdef AL_MEMORY_TRACKING printf("**al_malloc(%zu)\n", n); struct alloc_t a = { .ptr = ptr, @@ -68,14 +61,12 @@ void *al_malloc(size_t n) peak_allocated = currently_allocated; } al_array_push(allocations, a); -#endif return ptr; } void *al_calloc(size_t n, size_t size) { void *ptr = _al_calloc(n, size); -#ifdef AL_MEMORY_TRACKING printf("**al_calloc(%zu, %zu)\n", n, size); struct alloc_t a = { .ptr = ptr, @@ -87,14 +78,12 @@ void *al_calloc(size_t n, size_t size) peak_allocated = currently_allocated; } al_array_push(allocations, a); -#endif return ptr; } void *al_realloc(void *ptr, size_t n) { void *nptr = _al_realloc(ptr, n); -#ifdef AL_MEMORY_TRACKING printf("**al_realloc(%p, %zu)\n", ptr, n); for (u32 i = 0; i < allocations.size; i++) { struct alloc_t *a = &al_array_at(allocations, i); @@ -119,13 +108,11 @@ void *al_realloc(void *ptr, size_t n) al_array_push(allocations, a); } total_allocated += n; -#endif return nptr; } void al_free(void *ptr) { -#ifdef AL_MEMORY_TRACKING printf("**al_free(%p)\n", ptr); for (u32 i = 0; i < allocations.size; i++) { struct alloc_t *a = &al_array_at(allocations, i); @@ -135,7 +122,6 @@ void al_free(void *ptr) break; } } -#endif _al_free(ptr); } @@ -143,7 +129,6 @@ void al_free(void *ptr) s32 al_posix_memalign(void **ptr, size_t alignment, size_t n) { s32 res = _al_posix_memalign(ptr, alignment, n); -#ifdef AL_MEMORY_TRACKING size_t actual_size = (n + alignment) - ((n + alignment) % alignment); printf("**al_posix_memalign(%zu, %zu(%zu))\n", alignment, n, actual_size); struct alloc_t a = { @@ -156,22 +141,15 @@ s32 al_posix_memalign(void **ptr, size_t alignment, size_t n) peak_allocated = currently_allocated; } al_array_push(allocations, a); -#endif return res; } #endif void al_malloc_stats(u32 *current, u32 *peak, u32 *total) { -#ifdef AL_MEMORY_TRACKING *current = currently_allocated; *peak = peak_allocated; *total = total_allocated; -#else - *current = 0; - *peak = 0; - *total = 0; -#endif } void al_set_alloc(void *(*malloc_func)(size_t), void *(*calloc_func)(size_t, size_t), @@ -183,6 +161,7 @@ void al_set_alloc(void *(*malloc_func)(size_t), void *(*calloc_func)(size_t, siz _al_free = free_func; } #endif +#endif // Default to 4KB. size_t al_page_size = 0x1000; |