High Performance OPC UA Server SDK
1.2.0.193
|
Allocator for fixed size memory chunks. More...
Data Structures | |
struct | mem_objectpool |
This is the head structure of a memory pool, see also objectpool. More... | |
struct | mem_objectpool_static |
Structure for a static memory pool, see also objectpool. More... | |
Macros | |
#define | MEM_OBJECTPOOL_SIZE(num, size) ((num)*(size_align((size), sizeof(void *)))+sizeof(struct mem_objectpool)) |
Helper macro to compute pool sizes. More... | |
Functions | |
size_t | mem_objectpool_size (size_t num_objects, size_t object_size) |
Computes the size in bytes for num_objects objects in pool. More... | |
struct mem_objectpool * | mem_objectpool_init (size_t num_objects, size_t object_size, void *data, const char *name) |
Initializes the given memory data as object pool. More... | |
void | mem_objectpool_free_all (struct mem_objectpool *pool) |
Frees all object in an objectpool. More... | |
void | mem_objectpool_clear (struct mem_objectpool *pool) |
Clears an objectpool Depending on some defines this function prints objectpool statistics and checks for memory leaks. More... | |
void * | mem_objectpool_alloc (struct mem_objectpool *pool) |
Allocates one object in the given pool. More... | |
int | mem_objectpool_free (struct mem_objectpool *pool, void *el) |
Frees the given object. More... | |
int | mem_objectpool_free_index (struct mem_objectpool *pool, size_t idx) |
Frees the given object identified by its pool index. More... | |
void * | mem_objectpool_get (struct mem_objectpool *pool, size_t index) |
Returns the object at the given index. More... | |
size_t | mem_objectpool_indexof (const struct mem_objectpool *pool, const void *el) |
Returns the index of el in the pool. More... | |
bool | mem_objectpool_contains (const struct mem_objectpool *pool, const void *el) |
Verifies that el is an element of pool . More... | |
Allocator for fixed size memory chunks.
The objectpool is initialized with an amount of memory and a fixed size chunks size. Then mem_objectpool_get can be used to chunks from this memory.
#define MEM_OBJECTPOOL_SIZE | ( | num, | |
size | |||
) | ((num)*(size_align((size), sizeof(void *)))+sizeof(struct mem_objectpool)) |
Helper macro to compute pool sizes.
num | number of objects |
size | size of one object in bytes |
void* mem_objectpool_alloc | ( | struct mem_objectpool * | pool | ) |
Allocates one object in the given pool.
void mem_objectpool_clear | ( | struct mem_objectpool * | pool | ) |
Clears an objectpool Depending on some defines this function prints objectpool statistics and checks for memory leaks.
pool | Objectpool to clear. |
bool mem_objectpool_contains | ( | const struct mem_objectpool * | pool, |
const void * | el | ||
) |
Verifies that el
is an element of pool
.
int mem_objectpool_free | ( | struct mem_objectpool * | pool, |
void * | el | ||
) |
Frees the given object.
This adds el
to the pools freelist again.
void mem_objectpool_free_all | ( | struct mem_objectpool * | pool | ) |
Frees all object in an objectpool.
pool | Objectpool to clear. |
int mem_objectpool_free_index | ( | struct mem_objectpool * | pool, |
size_t | idx | ||
) |
Frees the given object identified by its pool index.
This simply avoids calling mem_objectpool_get() and mem_objectpool_free() and is a little bit more efficient.
void* mem_objectpool_get | ( | struct mem_objectpool * | pool, |
size_t | idx | ||
) |
Returns the object at the given index.
size_t mem_objectpool_indexof | ( | const struct mem_objectpool * | pool, |
const void * | el | ||
) |
Returns the index of el
in the pool.
struct mem_objectpool* mem_objectpool_init | ( | size_t | num_objects, |
size_t | object_size, | ||
void * | data, | ||
const char * | name | ||
) |
Initializes the given memory data
as object pool.
The size of data
must be big enough to hold num_objects*object_size+ sizeof(struct mem_objectpool).
Usage:
num_objects | Number of objects in pool. |
object_size | Size of one object in bytes. |
data | Pointer to memory area that should be managed by the pool. |
size_t mem_objectpool_size | ( | size_t | num_objects, |
size_t | object_size | ||
) |
Computes the size in bytes for num_objects
objects in pool.
This can be used by the caller to allocate the correct amount of memory for mem_objectpoolinit.