ITK Function Reference

(12.1)
Functions

Functions

BASE_UTILS_API void * MEM_alloc (int n_bytes)
 
BASE_UTILS_API void * MEM_crealloc (void *ptr, int n_items, int item_size)
 
BASE_UTILS_API void MEM_free (void *ptr)
 
BASE_UTILS_API void * MEM_realloc (void *ptr, int n_bytes)
 
BASE_UTILS_API char * MEM_sprintf (const char *format,...)
 
BASE_UTILS_API char * MEM_string_append (char *str, const char *appendage)
 
BASE_UTILS_API char * MEM_string_copy (const char *str)
 
BASE_UTILS_API char * MEM_string_nappend (char *str, const char *appendage, int n)
 
BASE_UTILS_API char * MEM_string_ncopy (const char *str, int n)
 
BASE_UTILS_API char * MEM_vsprintf (const char *format, va_list arg)
 

Detailed Description

These APIs use NX Storage Management (SM) functionalities, which offers several key features.
One of them is that the memory is returned to the Operating System once MEM_free is called. This means that the memory footprint of the application just not increases, but can also decrease significantly.

Function Documentation

BASE_UTILS_API void* MEM_alloc ( int  n_bytes)

Allocates a block on n_bytes bytes of memory.

Returns
On success, a pointer to the allocated block of memory is returned.
If n_bytes is zero or any error occurs, a 0 pointer is returned.
Parameters
n_bytes(I) number of bytes to be allocated.
BASE_UTILS_API void* MEM_crealloc ( void *  ptr,
int  n_items,
int  item_size 
)

Reallocates memory for an array and copies the existing data.
It works like MEM_realloc, but this ITK is for arrays. It also initializes extra space with zeroes.

Returns
A pointer to the new storage.
Parameters
ptr(I) Pointer to start of array to be reallocated.
n_items(I) New number of elements in the array.
item_size(I) New size, in bytes, for a single array element.
BASE_UTILS_API void MEM_free ( void *  ptr)

Frees the specified memory block.
The input pointer is expected to be a valid pointer allocated via relevant MEM_ API.
If ptr is a 0 pointer, no operation is performed.

Parameters
ptr(I) Pointer to the block to be freed.
BASE_UTILS_API void* MEM_realloc ( void *  ptr,
int  n_bytes 
)

Reallocates memory and copies the existing contents.
Allocates a new memory block of input size and copies contents of existing memory block.
Contents of extra memory in new block are undefined.

If the input pointer is 0, normal allocation is done.
If n_bytes is zero, existing storage is freed and 0 pointer is returned.
If n_bytes is less than current size of the memory block, the first n_bytes are copied.

Returns
A pointer to new memory block.
Parameters
ptr(I) Pointer to a memory block to be reallocated.
n_bytes(I) Number of bytes to be allocated to the new block.
BASE_UTILS_API char* MEM_sprintf ( const char *  format,
  ... 
)

Composes a string with the same text that would be printed if format was used on printf, but instead of being printed, the content is stored as a C string in the buffer pointed by string.

Note
The total size of the replaced string must not exceed 255 characters (not including the '\0' termination character).
char * someString = "Example";
double d = 90;
char* returnedString = MEM_sprintf ( " Some string %s , Some double %d \n", someString, d );
[...]
MEM_free( returnedString );
returnedString = 0;
Returns
The allocated pointer, which will need to be freed using MEM_free.
Parameters
format(I) String that contains some ASCII printf formatting: s (string), d (integer), etc.
BASE_UTILS_API char* MEM_string_append ( char *  str,
const char *  appendage 
)

Appends a string to an SM allocated string.
The string pointer str must not be used after this call.

Returns
A pointer to the new copy of the input string, in the same type of storage as before.
It needs to be freed using MEM_free.
Parameters
str(I) String in SM allocated memory to have another appended. It must not be NULL.
appendage(I) String to be appended to the end of str.
BASE_UTILS_API char* MEM_string_copy ( const char *  str)

Makes a copy of a '\0' terminated string.

Returns
A pointer to the copy of the input string.
It needs to be deallocated through a call to MEM_free.
Parameters
str(I) NULL terminated string to be copied.
BASE_UTILS_API char* MEM_string_nappend ( char *  str,
const char *  appendage,
int  n 
)

Appends at most n characters from a string to an SM allocated string.
The string pointer str must not be used after this call.

Returns
A pointer to the new copy of the input string, in the same type of storage as before.
It needs to be freed using MEM_free.
Parameters
str(I) String in SM allocated memory to have another appended. It must not be NULL.
appendage(I) String to be appended to the end of SM allocated string.
n(I) Number of characters to append.
BASE_UTILS_API char* MEM_string_ncopy ( const char *  str,
int  n 
)

Makes a copy of 'n' bytes of a '\0' terminated SM-allocated string.

Returns
A pointer to the NULL-terminated copy of the input string.
It needs to be freed using MEM_free.
Parameters
str(I) NULL terminated string to be copied.
n(I) Number of bytes to copy.
BASE_UTILS_API char* MEM_vsprintf ( const char *  format,
va_list  arg 
)

Composes the result of a formatted string and replacement arguments


The format string contains ASCII printf formatting (e.g. s), and the replacement parameters are in the variable argument arg.

Note
The total size of the replaced string must not exceed 255 characters (not including the '\0' termination character).
char * someString = "Example";
double d = 90;
char* returnedString = MEM_sprintf ( " Some string %s , Some double %d \n", someString, d );
[...]
MEM_free( returnedString );
returnedString = 0;
Returns
The allocated pointer, which will need to be freed using MEM_free.
Parameters
format(I) String that contains some ASCII printf formatting: s (string), d (integer), etc.
arg(I) variable arguments