Memory Management (C++ Language)
Precautions for API Usage
When memory is allocated by using HIAIMemory::HIAI_DMalloc, pay attention to the following issues about memory management:
- When memory to be automatically freed is allocated for host-device or device-host data sending, if a smart pointer is used, Matrix automatically frees the memory, so the destructor specified by the smart pointer must be null. If the pointer is not a smart pointer, Matrix automatically frees the memory.
- When memory to be manually freed is allocated for host-device or device-host data sending, if a smart pointer is used, you need to set the destructor to HIAIMemory::HIAI_DFree. If the pointer is not a smart pointer, you need to call HIAIMemory::HIAI_DFree to free the memory after data sending is complete.
- When memory to be manually freed is allocated, the SendData API cannot be called repeatedly to send data in the memory.
- When memory to be manually freed is allocated for host-device or device-host data sending, do not reuse the data in the memory before the memory is freed. If the memory is used for host-host or device-device data sending, the data in the memory can be reused before the memory is freed.
- When memory to be manually freed is allocated, if the SendData API is called to asynchronously send data, data in the memory cannot be modified after being sent.
If the HIAIMemory::HIAI_DVPP_DMalloc API is called to allocate memory for device-host data sending, the HIAIMemory::HIAI_DVPP_DFree API must be called to manually free the memory, because the HIAIMemory::HIAI_DVPP_DMalloc API does not automatically free the memory. If a smart pointer is used to store the allocated memory address, the destructor must be set to HIAIMemory::HIAI_DVPP_DFree.
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