doc
Functions
cynapses libc alloc functions

Functions

void * c_calloc (size_t count, size_t size)
 
void * c_malloc (size_t size)
 
void * c_realloc (void *ptr, size_t size)
 
char * c_strdup (const char *str)
 
char * c_strndup (const char *str, size_t size)
 

Detailed Description

Function Documentation

◆ c_calloc()

void* c_calloc ( size_t  count,
size_t  size 
)

Allocates memory for an array.

Allocates memory for an array of <count> elements of <size> bytes each and returns a pointer to the allocated memory. The memory is set to zero.

Parameters
countAmount of elements to allocate
sizeSize in bytes of each element to allocate.
Returns
A unique pointer value that can later be successfully passed to free(). If size or count is 0, NULL will be returned.

◆ c_malloc()

void* c_malloc ( size_t  size)

Allocates memory for an array.

Allocates <size> bytes of memory. The memory is set to zero.

Parameters
sizeSize in bytes to allocate.
Returns
A unique pointer value that can later be successfully passed to free(). If size or count is 0, NULL will be returned.

◆ c_realloc()

void* c_realloc ( void *  ptr,
size_t  size 
)

Changes the size of the memory block pointed to.

Newly allocated memory will be uninitialized.

Parameters
ptrPointer to the memory which should be resized.
sizeValue to resize.
Returns
If ptr is NULL, the call is equivalent to c_malloc(size); if size is equal to zero, the call is equivalent to free(ptr). Unless ptr is NULL, it must have been returned by an earlier call to c_malloc(), c_calloc() or c_realloc(). If the area pointed to was moved, a free(ptr) is done.

◆ c_strdup()

char* c_strdup ( const char *  str)

Duplicate a string.

The function returns a pointer to a newly allocated string which is a duplicate of the string str.

Parameters
strString to duplicate.
Returns
Returns a pointer to the duplicated string, or NULL if insufficient memory was available.

◆ c_strndup()

char* c_strndup ( const char *  str,
size_t  size 
)

Duplicate a string.

The function returns a pointer to a newly allocated string which is a duplicate of the string str of size bytes.

Parameters
strString to duplicate.
sizeSize of the string to duplicate.
Returns
Returns a pointer to the duplicated string, or NULL if insufficient memory was available. A terminating null byte '\0' is added.