Rate This Document
Findability
Accuracy
Completeness
Readability

kupl_hbw_malloc

Allocate OPM and lock the memory as much as possible.

Interface Definition

void* kupl_hbw_malloc(size_t size);

Parameters

Table 1 Parameter definition

Parameter

Type

Description

Input/Output

size

size_t

Size of the memory to be allocated.

Input

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_hbw_malloc(len);
    if (data == nullptr) {
        return 0;
    }
    kupl_hbw_free(data); 
    return 0; 
}
  • The preceding example demonstrates the process of allocating and then freeing the locked OPM.
  • The kupl_hbw_malloc function allocates memory of the size specified by len and locks the memory as much as possible.
  • The kupl_hbw_malloc function utilizes the memory locking mechanism to prevent the memory from being swapped to drives when conditions permit. The presence of an SDMA device in the environment is a prerequisite for locking the allocated memory.
  • If the kupl_hbw_malloc function fails to allocate the specified OPM, nullptr is returned.