S2OPC OPCUA Toolkit
Functions
sopc_mem_alloc.h File Reference

S2OPC memory allocation wrappers. More...

#include <stddef.h>

Go to the source code of this file.

Functions

void * SOPC_Malloc (size_t size)
 Allocates memory. More...
 
void SOPC_Free (void *ptr)
 Frees memory. More...
 
void * SOPC_Calloc (size_t nmemb, size_t size)
 Allocates memory. More...
 
void * SOPC_Realloc (void *ptr, size_t old_size, size_t new_size)
 Re-allocates memory. More...
 

Detailed Description

S2OPC memory allocation wrappers.

Function Documentation

◆ SOPC_Malloc()

void* SOPC_Malloc ( size_t  size)

Allocates memory.

This function acts as standard 'malloc' except that it ensures that a non-NULL pointer is returned even if the requested size is zero

Parameters
sizeThe amount of memory requested.
Returns
a pointer to the new allocated area, which has at least the requested size. The caller is responsible for calling SOPC_Free when the memory is no more required. NULL is returned if the memory cannot be allocated. The memory pointed to is not initialized.

◆ SOPC_Free()

void SOPC_Free ( void *  ptr)

Frees memory.

This function acts as standard 'free'.

Parameters
ptrThe previoulsy allocated pointer. Nothing is done if ptr is NULL. The caller shall ensure that the same pointer is not freed several times, and that only pointers previously allocated by SOPC_xalloc are passed as parameter.

◆ SOPC_Calloc()

void* SOPC_Calloc ( size_t  nmemb,
size_t  size 
)

Allocates memory.

This function acts as standard 'calloc'. However, if size is passed with the value "0", a non-null pointer shall be returned.

Parameters
sizeThe size of each element allocated
nmembThe number of adjacent element requested.
Returns
a pointer to the new allocated area (total size equals size *nmemb), which has at least the requested size. The caller is responsible for calling SOPC_Free when the memory is not more required. The allocated memory never takes into account alignment considerations, whatever the value of size is. NULL is returned if the memory cannot be allocated. The memory pointed to is initialized to '\0'

◆ SOPC_Realloc()

void* SOPC_Realloc ( void *  ptr,
size_t  old_size,
size_t  new_size 
)

Re-allocates memory.

Warning
Deprecated. New implementations should not use this function.

This function acts as realloc. However, realloc may not exist on the targetted architecture. In these cases, SOPC_Realloc maps to malloc + memcpy. For this operation, the current size of the buffer is required.