High Performance OPC UA Server SDK  1.1.0.158
objectpool

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_objectpoolmem_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...
 

Detailed Description

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.

Macro Definition Documentation

#define MEM_OBJECTPOOL_SIZE (   num,
  size 
)    ((num)*(size_align((size), sizeof(void *)))+sizeof(struct mem_objectpool))

Helper macro to compute pool sizes.

Parameters
numnumber of objects
sizesize of one object in bytes

Function Documentation

void* mem_objectpool_alloc ( struct mem_objectpool pool)

Allocates one object in the given pool.

Returns
Pointer to object of NULL if the pool has no more objects.
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.

Parameters
poolObjectpool to clear.
bool mem_objectpool_contains ( const struct mem_objectpool pool,
const void *  el 
)

Verifies that el is an element of pool.

Returns
Returns true if el is element of pool, false otherwise.
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.

Parameters
poolObjectpool 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.

Returns
Pointer to object or NULL if the index is out of range.
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:

1 static unsigned char g_pooldata[OBJECTPOOL_SIZE(100, sizeof(struct mytype)];
2 static struct mem_objectpool *g_pool;
3 
4 void init(void)
5 {
6  g_pool= mem_objectpool_init(100, sizeof(struct mytype), g_pooldata);
7 }
Parameters
num_objectsNumber of objects in pool.
object_sizeSize of one object in bytes.
dataPointer to memory area that should be managed by the pool.
Returns
A pointer to the initialized 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.