HIAIMemory::HIAI_DMalloc
Allocates memory blocks on the host side or device side to support efficient data transmission. This API is defined in ai_memory.h.
To allocate memory for DVPP on the device side, see HIAIMemory::HIAI_DVPP_DMalloc.
Application scenario:
With Matrix, this API is used to send large data from the host side to the device side. It must be used together with Macro: HIAI_REGISTER_SERIALIZE_FUNC.
For example, a 1080p or 4K image needs to be sent to the device side. To improve the data sending performance, you must register the structure serialization and deserialization functions through HIAI_REGISTER_SERIALIZE_FUNC. In addition, the large data block memory is allocated through HIAI_DMalloc. This greatly improves the data sending performance.

- This API deals with sending of large data between the host side and device side. You are advised not to use it as a common malloc API.
- For the sake of performance, this API pre-allocates memory. The actual memory size is different from the allocated memory size. The running time of this API may also change.
Syntax
static HIAI_StatusT HIAIMemory::HIAI_DMalloc (const uint32_t dataSize, void*& dataBuffer, const uint32_t timeOut = MALLOC_DEFAULT_TIME_OUT, uint32_t flag = MEMORY_ATTR_AUTO_FREE)
Parameter Description
Parameter |
Description |
Value Range |
---|---|---|
dataSize |
Size of a memory block |
|
dataBuffer |
Memory pointer |
- |
timeOut |
Timeout when memory fails to be allocated. The default value is MALLOC_DEFAULT_TIME_OUT (indicating 500 ms). |
- |
flag |
|
typedef enum { MEMORY_ATTR_NONE = 0, // The framework automatically frees the memory allocated by using DMalloc. MEMORY_ATTR_AUTO_FREE = (0x1 << 1), // DFree needs to be called manually to free the memory. MEMORY_ATTR_MANUAL_FREE = (0x1 << 2), MEMORY_ATTR_MAX } HIAI_MEMORY_ATTR; |
Return Value
For details about the returned error codes, see "Error Codes."
Error Codes
No. |
Error Code |
Description |
---|---|---|
1 |
HIAI_OK |
The running is OK. |
2 |
HIAI_GRAPH_NOT_EXIST |
The graph does not exist. |
3 |
HIAI_GRAPH_MEMORY_POOL_NOT_EXISTED |
The memory pool does not exist. |
4 |
HIAI_GRAPH_MALLOC_LARGER |
The buffer fails to be allocated because the size is larger than 256 MB. |
5 |
HIAI_MEMORY_POOL_UPDATE_FAILED |
The memory pool fails to be updated. |
6 |
HIAI_GRAPH_SENDMSG_FAILED |
The HDC module fails to send a message. |
7 |
HIAI_GRAPH_MEMORY_POOL_INITED |
The memory pool has been initialized. |
8 |
HIAI_GRAPH_NO_MEMORY |
There is no memory. |
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot