stumpless  2.1.0
Functions | Variables
memory.h File Reference
#include <stddef.h>
#include <stumpless/config.h>

Go to the source code of this file.

Functions

void stumpless_free_all (void)
 Closes the default target if it has been opened, frees all memory allocated internally, and performs any other necessary cleanup. More...
 
void stumpless_free_thread (void)
 Frees all memory allocated internally to the calling thread, and performs any other thread-specific cleanup. More...
 

Variables

void *(*)(size_t) stumpless_set_malloc (void *(*malloc_func)(size_t))
 Sets the function used by the library to allocate memory. More...
 
void(*)(void *) stumpless_set_free (void(*free_func)(void *))
 Sets the function used by the library to free memory. More...
 
void *(*)(void *, size_t) stumpless_set_realloc (void *(*realloc_func)(void *, size_t))
 Sets the function used by the library to reallocate memory. More...
 

Detailed Description

Functions for controlling memory allocation during execution.

Some of these functions allow memory allcoation to use custom functions. This might be useful if you have your own memory allocation routines or want to lay down your own controls over memory used by the library. For example, this capability is used extensively to test for error handling in memory allocation failure scenarios, as well as to ensure that the same amount of memory is freed as is allocated.

Function Documentation

◆ stumpless_free_all()

void stumpless_free_all ( void  )

Closes the default target if it has been opened, frees all memory allocated internally, and performs any other necessary cleanup.

This function serves as a final exit function, which should be called when an application using the library is preparing to exit or when the library is no longer needed. Before this function is called, all targets explicitly opened must be closed (with the exception of the default target, which is opened implicitly) and no pointers to any structs should be retained. Failing to do this will result in undefined behavior.

Calling other functions after a call to this function is acceptable, however execution times may be longer than usual as memory used to cache objects may need to be allocated. If other functions are called, this function should be called again before exit to ensure a memory leak does not exist.

Thread Safety: MT-Unsafe This function is not thread safe as it destroys resources that other threads might be using.

Async Signal Safety: AS-Unsafe heap This function is not safe to call from signal handlers due to the use of the memory deallocation function to release memory.

Async Cancel Safety: AC-Unsafe heap This function is not safe to call from threads that may be asynchronously cancelled, as the memory deallocation function may not be AC-Safe itself.

◆ stumpless_free_thread()

void stumpless_free_thread ( void  )

Frees all memory allocated internally to the calling thread, and performs any other thread-specific cleanup.

This function should be called in any thread that has used stumpless functions before it exits so that caches and other structures can be cleaned up. It is not a substitute for stumpless_free_all, but is called by it and can be left out if stumpless_free_all will be called later in the same thread.

Thread Safety: MT-Safe This function is thread safe as it only operates on thread-local resources.

Async Signal Safety: AS-Unsafe heap This function is not safe to call from signal handlers due to the use of the memory deallocation function to release memory.

Async Cancel Safety: AC-Unsafe heap This function is not safe to call from threads that may be asynchronously cancelled, as the memory deallocation function may not be AC-Safe itself.

Variable Documentation

◆ stumpless_set_free

void( *)( void * ) stumpless_set_free(void(*free_func)(void *))

Sets the function used by the library to free memory.

Thread Safety: MT-Unsafe This function is not thread safe as it changes the memory allocation scheme, which could cause an operation to use the old function for some allocation and the new function for others. If you need to set any of the memory management functions, it should be done before starting multiple threads with access to shared resources.

Async Signal Safety: AS-Unsafe This function is not safe to call from signal handlers for the same reason as it is not thread safe.

Async Cancel Safety: AC-Unsafe This function is not safe to call from threads that may be asynchronously cancelled, as the assignment is not guaranteed to be atomic.

Parameters
free_funcA pointer to the memory deallocation function that is desired. This function must have the same signature as the standard library free function (which is the default if this is not called).
Returns
The new deallocation function.

◆ stumpless_set_malloc

void*( *)( size_t ) stumpless_set_malloc(void *(*malloc_func)(size_t))

Sets the function used by the library to allocate memory.

Thread Safety: MT-Unsafe This function is not thread safe as it changes the memory allocation scheme, which could cause an operation to use the old function for some allocation and the new function for others. If you need to set any of the memory management functions, it should be done before starting multiple threads with access to shared resources.

Async Signal Safety: AS-Unsafe This function is not safe to call from signal handlers for the same reason as it is not thread safe.

Async Cancel Safety: AC-Unsafe This function is not safe to call from threads that may be asynchronously cancelled, as the assignment is not guaranteed to be atomic.

Parameters
malloc_funcA pointer to the allocation function that is desired. This function must have the same signature as the standard library malloc function (which is the default if this is not called).
Returns
The new allocation function.

◆ stumpless_set_realloc

void*( *)( void *, size_t ) stumpless_set_realloc(void *(*realloc_func)(void *, size_t))

Sets the function used by the library to reallocate memory.

Thread Safety: MT-Unsafe This function is not thread safe as it changes the memory allocation scheme, which could cause an operation to use the old function for some allocation and the new function for others. If you need to set any of the memory management functions, it should be done before starting multiple threads with access to shared resources.

Async Signal Safety: AS-Unsafe This function is not safe to call from signal handlers for the same reason as it is not thread safe.

Async Cancel Safety: AC-Unsafe This function is not safe to call from threads that may be asynchronously cancelled, as the assignment is not guaranteed to be atomic.

Parameters
realloc_funcA pointer to the memory reallocation function that is desired. This function must have the same signature as the standard library realloc function (which is the default if this is not called).
Returns
The new reallocation function.