Sturk 1.1.0
Publish-subscribe C implementation.
Loading...
Searching...
No Matches
mem.h File Reference

System memory allocator. More...

#include <stddef.h>
#include <stdint.h>
Include dependency graph for mem.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define st_alloc(size)   st_mem_alloc((size), __FILE__, __LINE__)
 
#define st_free(ptr)   st_mem_free((ptr), __FILE__, __LINE__)
 
#define ST_NEW(...)   ST__NEW(__VA_ARGS__, 1, )
 Allocate memory for a data type.
 

Functions

void * st_mem_alloc (size_t size, const char *file, int line)
 Allocate a contiguous memory region and optionally log a message on failure.
 
void st_mem_free (void *ptr, const char *file, int line)
 Free a contiguous memory region and optionally log a message on failure.
 
void st_mem_cleanup (void)
 If supported, free all the memory allocated with the system allocator.
 

Detailed Description

System memory allocator.

Macro Definition Documentation

◆ st_alloc

#define st_alloc (   size)    st_mem_alloc((size), __FILE__, __LINE__)
See also
st_mem_alloc()

◆ st_free

#define st_free (   ptr)    st_mem_free((ptr), __FILE__, __LINE__)
See also
st_mem_free()

◆ ST_NEW

#define ST_NEW (   ...)    ST__NEW(__VA_ARGS__, 1, )

Allocate memory for a data type.

A call ST_NEW(type, n) will alocate contiguous memory region of the length that is equal to the multiple of n and the size of type. The n argument is optional and by default it equals 1.

Function Documentation

◆ st_mem_alloc()

st_mem_alloc ( size_t  size,
const char *  file,
int  line 
)

Allocate a contiguous memory region and optionally log a message on failure.

Parameters
[in]sizeThe number of bytes to allocate.
[in]fileThe path to the file (for logging).
[in]lineThe line number (for logging).
Returns
The pointer to the allocated memory region.

◆ st_mem_free()

void st_mem_free ( void *  ptr,
const char *  file,
int  line 
)

Free a contiguous memory region and optionally log a message on failure.

Parameters
[in]ptrThe pointer to the memory region.
[in]fileThe path to the file (for logging).
[in]lineThe line number (for logging).