Memory management.
More...
Memory management.
◆ sb_t_malloc_check
◆ 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] | count | Number of elements to allocate. |
[in] | size | Size 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] | ptr | pointer 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] | 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.
- See also
- sb_free
-
sb_calloc
-
sb_realloc
-
sb_malloc_check_memory_leak
-
sb_malloc_check_memory_leak_reset
◆ sb_malloc_check_memory_leak()
Checks if the library has a memory leak.
- Parameters
-
[in] | check | Type 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_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] | ptr | Pointer 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] | size | New 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