SqueezeBrains SDK 1.13
Memory

Memory management. More...

Collaboration diagram for Memory:

Enumerations

enum  sb_t_malloc_check { SB_MALLOC_CHECK_MAIN_COUNTER = 0 , SB_MALLOC_CHECK_SECOND_COUNTER }
 Type of counter for the memory leak check. More...
 

Functions

void sb_free (void *ptr)
 Deallocates a memory block. More...
 
void * sb_malloc (size_t size)
 Allocates a memory block. More...
 
void * sb_calloc (size_t count, size_t size)
 Allocates and zero-initialize an array. More...
 
void * sb_realloc (void *ptr, size_t size)
 Reallocates a memory block. More...
 
sb_t_err sb_malloc_check_memory_leak (sb_t_malloc_check check)
 Checks if the library has a memory leak. More...
 
sb_t_err sb_malloc_check_memory_leak_reset (sb_t_malloc_check check)
 Resets the memory leak control. More...
 

Detailed Description

Memory management.

Enumeration Type Documentation

◆ sb_t_malloc_check

Type of counter for the memory leak check.

The values are 32 bits both for 32 and 64 bits library version.

See also
sb_malloc_check_memory_leak
sb_malloc_check_memory_leak_reset
Enumerator
SB_MALLOC_CHECK_MAIN_COUNTER 

The main counter.

SB_MALLOC_CHECK_SECOND_COUNTER 

The second counter.

Definition at line 6748 of file sb.h.

Function Documentation

◆ sb_calloc()

void * sb_calloc ( size_t  count,
size_t  size 
)

Allocates and zero-initialize an array.

Allocates a block of memory for an array of num elements, each of them size bytes long, and initializes all its bits to zero.
The effective result is the allocation of a zero-initialized memory block of (num*size) bytes.
If size is zero, the return value is NULL.

Parameters
[in]countNumber of elements to allocate.
[in]sizeSize of each element.
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.
See also
sb_free
sb_malloc
sb_realloc
sb_malloc_check_memory_leak
sb_malloc_check_memory_leak_reset

◆ sb_free()

void sb_free ( void *  ptr)

Deallocates a memory block.

A block of memory previously allocated by a call to sb_malloc , sb_calloc or sb_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 crashes. Notice that this function does not change the value of ptr itself, hence it still points to the same (now invalid) location.

Parameters
[in]ptrpointer to the buffer
See also
sb_malloc
sb_calloc
sb_realloc
sb_malloc_check_memory_leak
sb_malloc_check_memory_leak_reset

◆ sb_malloc()

void * sb_malloc ( size_t  size)

Allocates a 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 id NULL.

Parameters
[in]sizeSize 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.
See also
sb_free
sb_calloc
sb_realloc
sb_malloc_check_memory_leak
sb_malloc_check_memory_leak_reset

◆ sb_malloc_check_memory_leak()

sb_t_err sb_malloc_check_memory_leak ( sb_t_malloc_check  check)

Checks if the library has a memory leak.

Parameters
[in]checkType of check to be performed:
Returns
If successful, returns SB_ERR_NONE. Otherwise, it returns an error code sb_t_err. the return value is SB_ERR_MEMORY_LEAK if there is a memory leak
See also
sb_malloc_check_memory_leak_reset

◆ sb_malloc_check_memory_leak_reset()

sb_t_err sb_malloc_check_memory_leak_reset ( sb_t_malloc_check  check)

Resets the memory leak control.

Parameters
[in]checkType of reset to be performed:
Returns
If successful, returns SB_ERR_NONE. Otherwise, it returns an error code sb_t_err.
See also
sb_malloc_check_memory_leak

◆ sb_realloc()

void * sb_realloc ( void *  ptr,
size_t  size 
)

Reallocates a 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 sb_malloc , assigning a new block of size bytes and returning a pointer to its beginning.

Parameters
[in]ptrPointer to a memory block previously allocated with sb_malloc, sb_calloc or sb_realloc .
Alternatively, this can be a null pointer, in which case a new block is allocated (as if sb_malloc was called).
[in]sizeNew size for the memory block, in bytes.
See also
sb_free
sb_malloc
sb_calloc
sb_malloc_check_memory_leak
sb_malloc_check_memory_leak_reset