Tilde Friends
Memory management

Classes

struct  _tf_mem_allocation_t
 

Typedefs

typedef struct JSMallocFunctions JSMallocFunctions
 
typedef struct _tf_mem_allocation_t tf_mem_allocation_t
 

Functions

void tf_mem_startup (bool tracking)
 
void tf_mem_shutdown ()
 
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 ()
 
void tf_mem_replace_sqlite_allocator ()
 
size_t tf_mem_get_sqlite_malloc_size ()
 
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)
 
void * tf_resize_vec (void *ptr, size_t size)
 
void tf_get_js_malloc_functions (JSMallocFunctions *out)
 
size_t tf_mem_get_js_malloc_size ()
 
void tf_mem_walk_allocations (void(*callback)(void *ptr, size_t size, int frames_count, void *const *frames, void *user_data), void *user_data)
 
tf_mem_allocation_ttf_mem_summarize_allocations (int *out_count)
 

Detailed Description

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.

Typedef Documentation

◆ JSMallocFunctions

JS malloc functions.

◆ tf_mem_allocation_t

Information about a memory allocation.

Function Documentation

◆ tf_free()

void tf_free ( void *  ptr)

Free memory allocated by tf_malloc() or tf_realloc().

Parameters
ptrThe allocation.

◆ tf_get_js_malloc_functions()

void tf_get_js_malloc_functions ( JSMallocFunctions out)

Populate a struct with custom JS allocation functions.

Parameters
[out]outThe struct to receive the functions.

◆ tf_malloc()

void * tf_malloc ( size_t  size)

Allocate memory. Like malloc() but with more tracking.

Parameters
sizeThe 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()

void tf_mem_shutdown ( )

Clean up the memory system.

◆ tf_mem_startup()

void tf_mem_startup ( bool  tracking)

Do early setup for memory tracking.

Parameters
trackingWhether tracking will be enabled, which adds a time and memory cost of storing stack traces for every allocation.

◆ tf_mem_summarize_allocations()

tf_mem_allocation_t * tf_mem_summarize_allocations ( int *  out_count)

Generate a list of live allocations.

Parameters
[out]out_countThe 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
callbackThe callback to call.
user_dataUser 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
ptrThe previously allocated memory or NULL.
sizeThe 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
ptrThe allocation to resize.
sizeThe desired new size.
Returns
The new allocation.

◆ tf_strdup()

char * tf_strdup ( const char *  string)

Duplicate a string.

Parameters
stringThe string to copy.
Returns
The newly allocated string. Free with tf_free().