Memory allocation
-
void *ulib_malloc(size_t size)
Allocates size bytes of uninitialized storage.
Note
The returned object must be destroyed by calling
ulib_free()
.- Parameters:
size – Number of bytes to allocate.
- Returns:
Pointer to the beginning of the allocated memory, or NULL on failure.
-
void *ulib_calloc(size_t num, size_t size)
Allocates memory for an array of num objects of size and initializes all bytes in the allocated storage to zero.
Note
The returned object must be destroyed by calling
ulib_free()
.- Parameters:
num – Number of objects.
size – Size of each object.
- Returns:
Pointer to the beginning of the allocated memory, or NULL on failure.
-
void *ulib_realloc(void *ptr, size_t size)
Reallocates the given memory area with a new size.
Note
The returned object must be destroyed by calling
ulib_free()
.- Parameters:
ptr – Pointer to the memory area to reallocate.
size – New size of the memory area in bytes.
- Returns:
Pointer to the beginning of the allocated memory, or NULL on failure.
-
void ulib_free(void *ptr)
Deallocates the given memory area.
- Parameters:
ptr – Pointer to the memory area to deallocate.
-
void *ulib_stackalloc(size_t size)
Allocates size bytes of uninitialized storage on the stack.
Note
You must not free the returned pointer.
- Parameters:
size – Number of bytes to allocate.
- Returns:
Pointer to the beginning of the allocated memory.
-
void *ulib_alloc(T *ptr)
Allocates memory to hold the type of the pointed variable.
Note
The returned object must be destroyed by calling
ulib_free()
.- Parameters:
ptr – Typed pointer to the variable.
- Returns:
Pointer to the allocated memory area.
-
void *ulib_alloc_array(T *ptr, size_t size)
Allocates an array.
Note
The returned object must be destroyed by calling
ulib_free()
.- Parameters:
ptr – Typed variable that will hold the pointer to the allocated memory area.
size – Maximum number of elements that the array can hold.
- Returns:
Pointer to the allocated memory area.
-
void *ulib_calloc_array(T *ptr, size_t size)
Allocates an array and initializes its storage to zero.
Note
The returned object must be destroyed by calling
ulib_free()
.- Parameters:
ptr – Typed variable that will hold the pointer to the allocated memory area.
size – Maximum number of elements that the array can hold.
- Returns:
Pointer to the allocated memory area.
-
void *ulib_realloc_array(T *ptr, size_t size)
Reallocates a previously allocated array.
Note
The returned object must be destroyed by calling
ulib_free()
.- Parameters:
ptr – Typed pointer to the allocated memory area.
size – Maximum number of elements that the array can hold.
- Returns:
Pointer to the allocated memory area.