2022-06-04 13:04:51 -04:00
|
|
|
#pragma once
|
|
|
|
|
2024-02-20 21:41:37 -05:00
|
|
|
/**
|
|
|
|
** \defgroup mem Memory management
|
|
|
|
** tf_malloc() and friends use malloc() behind the scenes but optionally
|
|
|
|
** track memory per system (OpenSSL, sqlite, libuv, ...) and store callstacks
|
|
|
|
** to help debug leaks.
|
|
|
|
** @{
|
|
|
|
*/
|
|
|
|
|
2023-02-18 16:00:39 -05:00
|
|
|
#include <stdbool.h>
|
2022-06-04 13:04:51 -04:00
|
|
|
#include <stddef.h>
|
2023-02-18 16:00:39 -05:00
|
|
|
#include <stdint.h>
|
2022-06-04 13:04:51 -04:00
|
|
|
|
2022-06-20 13:57:07 -04:00
|
|
|
typedef struct JSMallocFunctions JSMallocFunctions;
|
|
|
|
|
2023-02-18 16:00:39 -05:00
|
|
|
void tf_mem_startup(bool tracking);
|
|
|
|
void tf_mem_shutdown();
|
|
|
|
|
2022-06-04 13:04:51 -04:00
|
|
|
void tf_mem_replace_uv_allocator();
|
|
|
|
size_t tf_mem_get_uv_malloc_size();
|
|
|
|
|
|
|
|
void tf_mem_replace_tls_allocator();
|
|
|
|
size_t tf_mem_get_tls_malloc_size();
|
|
|
|
|
2023-02-18 14:14:06 -05:00
|
|
|
void tf_mem_replace_sqlite_allocator();
|
|
|
|
size_t tf_mem_get_sqlite_malloc_size();
|
|
|
|
|
2022-06-04 13:04:51 -04:00
|
|
|
size_t tf_mem_get_tf_malloc_size();
|
|
|
|
|
|
|
|
void* tf_malloc(size_t size);
|
|
|
|
void* tf_realloc(void* ptr, size_t size);
|
|
|
|
void tf_free(void* ptr);
|
|
|
|
char* tf_strdup(const char* string);
|
2022-06-17 17:18:10 -04:00
|
|
|
|
|
|
|
void* tf_resize_vec(void* ptr, size_t size);
|
2022-06-20 13:57:07 -04:00
|
|
|
|
|
|
|
void tf_get_js_malloc_functions(JSMallocFunctions* out);
|
|
|
|
size_t tf_mem_get_js_malloc_size();
|
2023-02-18 16:00:39 -05:00
|
|
|
|
|
|
|
void tf_mem_walk_allocations(void (*callback)(void* ptr, size_t size, int frames_count, void* const* frames, void* user_data), void* user_data);
|
|
|
|
|
|
|
|
typedef struct _tf_mem_allocation_t
|
|
|
|
{
|
|
|
|
uint32_t stack_hash;
|
|
|
|
int count;
|
|
|
|
size_t size;
|
|
|
|
void* frames[32];
|
|
|
|
int frames_count;
|
|
|
|
} tf_mem_allocation_t;
|
|
|
|
|
|
|
|
tf_mem_allocation_t* tf_mem_summarize_allocations(int* out_count);
|
2024-02-20 21:41:37 -05:00
|
|
|
|
|
|
|
/** @} */
|