我要评分
获取效率
正确性
完整性
易理解

kupl_malloc

Allocate memory using a specific allocation policy and lock the allocated memory as much as possible.

Interface Definition

void* kupl_malloc(kupl_mem_kind_t kind, size_t size);

Parameters

Table 1 Parameter definition

Parameter

Type

Description

Input/Output

kind

kupl_mem_kind_t

Memory allocation policy to be used.

Input

size

size_t

Size of the memory to be allocated.

Input

Table 2 kupl_mem_kind_t enumerations

Enumerated Value

Description

KUPL_MEM_DEFAULT

Allocates memory using the default allocation policy.

KUPL_MEM_LARGE_CAP

Allocates memory from the nearest high-capacity memory node. If the allocation fails, nullptr is returned and an error is reported.

KUPL_MEM_HIGH_BW

Allocates memory from the nearest on-chip memory node. If the allocation fails, nullptr is returned and an error is reported.

Return Value

  • Success: pointer to the allocated memory
  • Failure: nullptr

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
#include <stdio.h> 
#include <stdlib.h>
#include "kupl.h" 

int main() 
{ 
    int len = 1024; 
    char *data = (char *)kupl_malloc(KUPL_MEM_DEFAULT, len);
    if (data == nullptr) {
        return 0;
    }
    kupl_free(KUPL_MEM_DEFAULT, data); 
    return 0; 
}
  • The preceding example demonstrates the process of allocating and then freeing the locked memory.
  • The kupl_malloc function is used to allocate a memory space of size len and lock it if possible. The default memory allocation policy of the system is used.
  • The kupl_malloc function locks the allocated memory if possible. The presence of an SDMA device in the environment is a necessary condition for locking the allocated memory.