Main Page | Modules | Class Hierarchy | Alphabetical List | Data Structures | File List | Data Fields | Globals | Related Pages

Malloc - Memory management


Files

file  otMalloc.h
 memory management library.

Modules

 Version History

Functions

void _initMalloc ()
 Init malloc functions. This function must be called at setup time as first.
U32 _memFree ()
 Memory free.
void _free (void *ptr)
 Deallocate memory block. A block of memory previously allocated by a call to malloc, calloc or realloc is deallocated, making it available again for further allocations. If ptr does not point to a block of memory allocated with the above functions, it causes undefined behavior. If ptr is a null pointer, the function does nothing. Notice that this function does not change the value of ptr itself, hence it still points to the same (now invalid) location.
void * _malloc (U32 size)
 Allocate memory block. Allocates a block of size bytes of memory, returning a pointer to the beginning of the block. The content of the newly allocated block of memory is not initialized, remaining with indeterminate values. If size is zero, the return value depends on the particular library implementation (it may or may not be a null pointer), but the returned pointer shall not be dereferenced.
void * _calloc (U32 size)
 Allocate and zero-initialize array. Allocates a block of memory for an array of size bytes long, and initializes all its bits to zero.
void * _realloc (void *ptr, U32 size)
 Reallocate memory block. Changes the size of the memory block pointed to by ptr. The function may move the memory block to a new location (whose address is returned by the function). The content of the memory block is preserved up to the lesser of the new and old sizes, even if the block is moved to a new location. If the new size is larger, the value of the newly allocated portion is indeterminate. In case that ptr is a null pointer, the function behaves like _malloc, assigning a new block of size bytes and returning a pointer to its beginning.
void * _reallocf (void *ptr, U32 size)

Function Documentation

void* _calloc U32  size  ) 
 

Parameters:
size Size of the memory block, in bytes.
Returns:
n success, a pointer to the memory block allocated by the function. The type of this pointer is always void*, which can be cast to the desired type of data pointer in order to be dereferenceable. If the function failed to allocate the requested block of memory, a null pointer is returned.

void _free void *  ptr  ) 
 

Parameters:
ptr Pointer to a memory block previously allocated with _malloc, _calloc or _realloc.

void _initMalloc  ) 
 

void* _malloc U32  size  ) 
 

Parameters:
size Size of the memory block, in bytes.
Returns:
On success, a pointer to the memory block allocated by the function. The type of this pointer is always void*, which can be cast to the desired type of data pointer in order to be dereferenceable. If the function failed to allocate the requested block of memory, a null pointer is returned.

U32 _memFree  ) 
 

Returns:
Memory free as bytes

void* _realloc void *  ptr,
U32  size
 

Parameters:
ptr Pointer to a memory block previously allocated with _malloc, _calloc or _realloc. Alternatively, this can be a null pointer, in which case a new block is allocated (as if malloc was called).
size New size for the memory block, in bytes.
Returns:
A pointer to the reallocated memory block, which may be either the same as ptr or a new location. The type of this pointer is void*, which can be cast to the desired type of data pointer in order to be dereferenceable.

void* _reallocf void *  ptr,
U32  size
 

The _reallocf() function changes the size of the previously allocated memory referenced by ptr to size bytes. The contents of the memory are unchanged up to the lesser of the new and old sizes. If the new size is larger, the contents of the newly allocated portion of the memory are undefined. Upon success, the memory referenced by ptr is freed and a pointer to the newly allocated memory is returned. Note that _reallocf() may move the memory allocation, resulting in a different return value than ptr. If ptr is NULL, the _reallocf() function behaves identically to _malloc() for the specified size. Upon failure, when the requested memory cannot be allocated, the passed pointer is freed to ease the problems with traditional coding styles for reallocf() causing memory leaks in libraries.

Parameters:
ptr Pointer to a memory block previously allocated with _malloc, _calloc or _realloc. Alternatively, this can be a null pointer, in which case a new block is allocated (as if _malloc was called).
size New size for the memory block, in bytes.
Returns:
A pointer to the reallocated memory block, which may be either the same as ptr or a new location. The type of this pointer is void*, which can be cast to the desired type of data pointer in order to be dereferenceable.
footer

otStudio - Library Reference - (C) 2020-25 Officina Turini, All Rights Reserved
Document built with Doxygen 1.4.0