memkind 内存申请和释放

#include <memkind.h>

memkind_create_pmem

///
/// \brief Create a new PMEM (file-backed) kind of given size on top of a temporary file
///        in the given directory dir
/// \note STANDARD API
/// \param dir path to specified directory to temporary file
/// \param max_size size limit for kind
/// \param kind pointer to kind which will be created
/// \return Memkind operation status, MEMKIND_SUCCESS on success, other values on failure
///
int memkind_create_pmem(const char *dir, size_t max_size, memkind_t *kind);

示例

memkind *pmemkind = NULL;
int error = memkind_create_pmem(str, sz, &pmemkind);
  if (error) {
    jclass exceptionCls = env->FindClass("java/lang/Exception");
    env->ThrowNew(exceptionCls,
      "Persistent initialize failed! Please check the path permission.");
  }

memkind_malloc

///
/// \brief Allocates size bytes of uninitialized storage of the specified kind
/// \note STANDARD API
/// \param kind specified memory kind
/// \param size number of bytes to allocate
/// \return Pointer to the allocated memory
///
void *memkind_malloc(memkind_t kind, size_t size);

memkind_malloc_usable_size

单次申请后的对其值。

///
/// \brief Obtain size of block of memory allocated with the memkind API
/// \note STANDARD API
/// \param kind specified memory kind
/// \param ptr pointer to the allocated memory
/// \return Number of usable bytes
///
size_t memkind_malloc_usable_size(memkind_t kind, void *ptr);

memkind_free

///
/// \brief Free the memory space of the specified kind pointed by ptr
/// \note STANDARD API
/// \param kind specified memory kind
/// \param ptr pointer to the allocated memory
///
void memkind_free(memkind_t kind, void *ptr);

猜你喜欢

转载自blog.csdn.net/zhixingheyi_tian/article/details/84751551