High Performance OPC UA Server SDK  1.2.0.193
memory_layout

Functions for managing the memory layout. More...

Data Structures

struct  memory_pool_config
 Configures the size of one memory pool. More...
 
struct  memory_layout
 Memory layout structure. More...
 

Macros

#define MEMORY_INVALID_INDEX   (size_t)-1
 

Functions

unsigned int memory_uniqueid (void)
 
unsigned int ipc_counter (void)
 
int memory_layout_init (struct memory_layout *config)
 
void memory_layout_clear (struct memory_layout *config)
 The clear functions is actually not necessary, because the memory is provided by the caller of memory_layout_init. More...
 
void memory_layout_set (void *mem)
 Set existing and initialized memory. More...
 
void * memory_layout_get (void)
 Returns the address of the global memory segment. More...
 
void memory_layout_set_prop (unsigned int index, void *data)
 Stores a shared memory property. More...
 
void * memory_layout_get_prop (unsigned int index)
 Returns a shared memory property. More...
 
void memory_layout_set_prop_uint (unsigned int index, unsigned int val)
 Stores a shared memory property from type unsigned int. More...
 
unsigned int memory_layout_get_prop_uint (unsigned int index)
 Returns a shared memory property from type unsigned int. More...
 
void memory_layout_set_prop_int (unsigned int index, int val)
 Stores a shared memory property from type int. More...
 
int memory_layout_get_prop_int (unsigned int index)
 Returns a shared memory property from type int. More...
 
struct mem_objectpoolmemory_get_pool (unsigned int pool_id)
 Returns the object pool for the given pool_id. More...
 
void * memory_pool_alloc (unsigned int pool_id)
 Allocates one object of the given pool. More...
 
void * memory_pool_calloc (unsigned int pool_id)
 Allocates one object of the given pool and zeros the memory. More...
 
void memory_pool_free (unsigned int pool_id, void *ptr)
 Give the object ptr back to the memory pool. More...
 
void * memory_pool_get (unsigned int pool_id, int index)
 Returns the object with the given index from the memory pool. More...
 
size_t memory_pool_indexof (unsigned int pool_id, const void *ptr)
 This returns the index of an object inside a memory pool. More...
 
void * memory_malloc (size_t size)
 
void memory_free (void *ptr)
 
void * memory_calloc (size_t nmemb, size_t size)
 
void * memory_realloc (void *ptr, size_t size)
 

Detailed Description

Functions for managing the memory layout.

The UA SDK makes use of various memory pools, which need to be setup properly. For this one big block of memory is allocated at startup and is then devided into several memory pools.

Function Documentation

struct mem_objectpool* memory_get_pool ( unsigned int  pool_id)

Returns the object pool for the given pool_id.

The pool_id must be within 1..num_pools-1 (0=heap).

void memory_layout_clear ( struct memory_layout config)

The clear functions is actually not necessary, because the memory is provided by the caller of memory_layout_init.

But we can do some statistic and memory leak detection here.

void* memory_layout_get ( void  )

Returns the address of the global memory segment.

void* memory_layout_get_prop ( unsigned int  index)

Returns a shared memory property.

Parameters
indexproperty index
Returns
Property value or NULL if index is invalid.
int memory_layout_get_prop_int ( unsigned int  index)

Returns a shared memory property from type int.

Parameters
indexproperty index
Returns
Property value or 0 if index is invalid.
unsigned int memory_layout_get_prop_uint ( unsigned int  index)

Returns a shared memory property from type unsigned int.

Parameters
indexproperty index
Returns
Property value or 0 if index is invalid.
int memory_layout_init ( struct memory_layout config)

< sum of all pools + header for validation in SHM

< sum of all pools in private memory

< size of memory header

< size of heap memory pool

< size of object pool

void memory_layout_set ( void *  mem)

Set existing and initialized memory.

This is used when opening an existing shared memory segment, which was already initialized by the master process.

void memory_layout_set_prop ( unsigned int  index,
void *  data 
)

Stores a shared memory property.

Parameters
indexproperty index.
datauser data pointer.
void memory_layout_set_prop_int ( unsigned int  index,
int  val 
)

Stores a shared memory property from type int.

Parameters
indexproperty index.
valuser data.
void memory_layout_set_prop_uint ( unsigned int  index,
unsigned int  val 
)

Stores a shared memory property from type unsigned int.

Parameters
indexproperty index.
valuser data.
void* memory_pool_alloc ( unsigned int  pool_id)

Allocates one object of the given pool.

Parameters
pool_idmemory pool identifier
Returns
Uninitialized object or NULL if pool is empty.

Allocates one object of the given pool.

These functions are needed buffer_alloc in based library, but are not necessary in xml2bin.

void* memory_pool_calloc ( unsigned int  pool_id)

Allocates one object of the given pool and zeros the memory.

Parameters
pool_idmemory pool identifier
Returns
Zero initialized object or NULL if pool is empty.
void memory_pool_free ( unsigned int  pool_id,
void *  ptr 
)

Give the object ptr back to the memory pool.

Parameters
pool_idmemory pool identifier
ptrobject to free
void* memory_pool_get ( unsigned int  pool_id,
int  index 
)

Returns the object with the given index from the memory pool.

This is used for fast index based access of memory pool objects.

See also
memory_pool_indexof
size_t memory_pool_indexof ( unsigned int  pool_id,
const void *  ptr 
)

This returns the index of an object inside a memory pool.

This index can be used as a handle to the object.

See also
memory_pool_get
Returns
index of ptr in pool or MEMORY_INVALID_INDEX if the operation fails.