Malloc and Free
- Allocate memory aligned to a specified byte:
void* HMPP_Malloc(int32_t len);
- Release memory:
void HMPP_Free(void* ptr);
Parameters
Parameter |
Description |
Value Range |
Input/Output |
|---|---|---|---|
len |
Byte length (HMPP_Malloc function) Array length (HMPPS_Malloc_xxx function) |
> 0 |
Input |
ptr |
Pointer to the memory block to be released (Free function) |
The value cannot be NULL. |
Input |
Return Value
HMPP_Malloc function:
- Success: The start pointer to the allocated memory is returned.
- Failure: NULL
Note
The input parameter of the Free function must be the return value of the Malloc function.
Example
#define BUFFER_SIZE 100
void Malloc_Free_Example() {
void *ptr = HMPP_Malloc(BUFFER_SIZE);
int suc = (ptr != NULL);
HMPP_Free(ptr);
uint8_t *ptrs = HMPPS_Malloc_8u(BUFFER_SIZE);
suc = suc & (ptrs != NULL);
HMPPS_Free(ptrs);
printf("%d", suc);
}
Output:
1
Parent topic: Basic Functions