MemoryData

Function

Defines memory management.

Structure Definition

struct MemoryData {
    enum MemoryType {
        MEMORY_HOST = 0,
        MEMORY_DEVICE,
        MEMORY_DVPP,
        MEMORY_HOST_MALLOC,
        MEMORY_HOST_NEW,
    };
    MemoryData() = default;
    MemoryData(size_t size, MemoryType type = MEMORY_HOST, int32_t deviceId = 0)
        : size(size), deviceId(deviceId), type(type) {}
    MemoryData(void* ptrData, size_t size, MemoryType type = MEMORY_HOST, int32_t deviceId = 0)
        : ptrData(ptrData), size(size), deviceId(deviceId), type(type) {}
    void* ptrData;
    size_t size;
    int32_t deviceId;
    MemoryType type;
    APP_ERROR (*free)(void*) = nullptr;
};

Parameter Description

Parameter

Input/Output

Description

ptrData

Output

Address of the memory for storing data

size

Input

Memory size, in bytes.

The size must be the same as the actual memory size. Otherwise, a core dump may occur.

deviceId

Input

Device ID

type

Input

Type of the memory applied for:

  • MEMORY_HOST corresponds to the host.
  • MEMORY_DEVICE corresponds to the device.
  • MEMORY_DVPP corresponds to the DVPP.
  • MEMORY_HOST_MALLOC corresponds to memory allocated by malloc.
  • MEMORY_HOST_NEW corresponds to memory allocated by new.

free

Output

ptrData pointer release function

MemoryData(size_t size, MemoryType type = MEMORY_HOST, size_t deviceId = 0)

-

The first form for defining a structure

MemoryData(void* ptrData, size_t size, MemoryType type = MEMORY_HOST, size_t deviceId = 0)

-

The second form for defining a structure