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.
◆ JSMallocFunctions
◆ tf_mem_allocation_t
Information about a memory allocation.
◆ tf_free()
void tf_free |
( |
void * |
ptr | ) |
|
◆ tf_get_js_malloc_functions()
Populate a struct with custom JS allocation functions.
- Parameters
-
[out] | out | The struct to receive the functions. |
◆ tf_malloc()
void * tf_malloc |
( |
size_t |
size | ) |
|
Allocate memory. Like malloc() but with more tracking.
- Parameters
-
size | The number of bytes to allocate. |
- Returns
- The allocated memory.
◆ tf_mem_get_js_malloc_size()
size_t tf_mem_get_js_malloc_size |
( |
| ) |
|
Get the number of bytes currently allocated by JS allocators.
- Returns
- The allocated size in bytes.
◆ tf_mem_get_sqlite_malloc_size()
size_t tf_mem_get_sqlite_malloc_size |
( |
| ) |
|
Get the number of bytes currently allocated by SQLite.
- Returns
- The allocated size in bytes.
◆ tf_mem_get_tf_malloc_size()
size_t tf_mem_get_tf_malloc_size |
( |
| ) |
|
Get the number of bytes currently allocated by tf_malloc().
- Returns
- The allocated size in bytes.
◆ tf_mem_get_tls_malloc_size()
size_t tf_mem_get_tls_malloc_size |
( |
| ) |
|
Get the number of bytes currently allocated by OpenSSL.
- Returns
- The allocated size in bytes.
◆ tf_mem_get_uv_malloc_size()
size_t tf_mem_get_uv_malloc_size |
( |
| ) |
|
Get the number of bytes currently allocated by libuv.
- Returns
- The allocated size in bytes.
◆ tf_mem_replace_sqlite_allocator()
void tf_mem_replace_sqlite_allocator |
( |
| ) |
|
Register a custom allocator with SQLite.
◆ tf_mem_replace_tls_allocator()
void tf_mem_replace_tls_allocator |
( |
| ) |
|
Register a custom allocator with OpenSSL.
◆ tf_mem_replace_uv_allocator()
void tf_mem_replace_uv_allocator |
( |
| ) |
|
Register a custom allocator with libuv.
◆ tf_mem_shutdown()
Clean up the memory system.
◆ tf_mem_startup()
void tf_mem_startup |
( |
bool |
tracking | ) |
|
Do early setup for memory tracking.
- Parameters
-
tracking | Whether tracking will be enabled, which adds a time and memory cost of storing stack traces for every allocation. |
◆ tf_mem_summarize_allocations()
Generate a list of live allocations.
- Parameters
-
[out] | out_count | The number of allocations returned. |
- Returns
- An array of allocation information. Free with tf_free().
◆ tf_mem_walk_allocations()
void tf_mem_walk_allocations |
( |
void(*)(void *ptr, size_t size, int frames_count, void *const *frames, void *user_data) |
callback, |
|
|
void * |
user_data |
|
) |
| |
Call a function for every live memory allocation.
- Parameters
-
callback | The callback to call. |
user_data | User data to pass to the callback. |
◆ tf_realloc()
void * tf_realloc |
( |
void * |
ptr, |
|
|
size_t |
size |
|
) |
| |
Reallocate memory. Like realloc() but with more tracking.
- Parameters
-
ptr | The previously allocated memory or NULL. |
size | The new desired size. |
- Returns
- The new allocation.
◆ tf_resize_vec()
void * tf_resize_vec |
( |
void * |
ptr, |
|
|
size_t |
size |
|
) |
| |
Resize a vector. Like tf_realloc() but overallocatess and prefers not to shrink in order to speed up repeated growth.
- Parameters
-
ptr | The allocation to resize. |
size | The desired new size. |
- Returns
- The new allocation.
◆ tf_strdup()
char * tf_strdup |
( |
const char * |
string | ) |
|
Duplicate a string.
- Parameters
-
string | The string to copy. |
- Returns
- The newly allocated string. Free with tf_free().