---
name: "pmemallocator"
section: "3"
platform: "linux"
package: "libmemkind-dev"
version: "1.14.0-2"
release: "Debian 12 (Bookworm)"
platforms: ["linux"]
url: "https://new.carta.tech/pmemallocator"
---

# pmemallocator(3)

The C++ allocator compatible with the C++ standard library allocator concepts Note: pmem\_allocator.h functionality is considered as stable API (STANDARD API).

## NAME

libmemkind::pmem::allocator\<T\> - The C++ allocator compatible with the C++ standard library allocator concepts\
 **Note:** *pmem\_allocator.h* functionality is considered as stable API (STANDARD API).

## SYNOPSIS

```
#include <pmem_allocator.h>

Link with -lmemkind

libmemkind::pmem::allocator(const char *dir, size_t max_size);
libmemkind::pmem::allocator(const char &dir, size_t max_size, libmemkind::allocation_policy alloc_policy);
libmemkind::pmem::allocator(const std::string &dir, size_t max_size);
libmemkind::pmem::allocator(const std::string &dir, size_t max_size, libmemkind::allocation_policy alloc_policy);
template <typename U> libmemkind::pmem::allocator<T>::allocator(const libmemkind::pmem::allocator<U>&) noexcept;
template <typename U> libmemkind::pmem::allocator(const allocator<U>&& other) noexcept;
libmemkind::pmem::allocator<T>::~allocator();
T *libmemkind::pmem::allocator<T>::allocate(std::size_t n) const;
void libmemkind::pmem::allocator<T>::deallocate(T *p, std::size_t n) const;
template <class U, class... Args> void libmemkind::pmem::allocator<T>::construct(U *p, Args... args) const;
void libmemkind::pmem::allocator<T>::destroy(T *p) const;
```

## DESCRIPTION

The **libmemkind::pmem::allocator\<T\>** is intended to be used with STL containers to allocate persistent memory. Memory management is based on memkind\_pmem (memkind library). Refer [**memkind\_pmem**(3)](/memkind_pmem/3.md) and [**memkind**(3)](/memkind/3.md) man page for more details.

The **libmemkind::allocation\_policy** specifies allocator memory usage policy, which allows to tune up memory utilization. The available types of allocator usage policy:

**libmemkind::allocation\_policy::DEFAULT** Default allocator memory usage policy.

**libmemkind::allocation\_policy::CONSERVATIVE** Conservative allocator memory usage policy - prioritize memory usage at cost of performance.

All public member types and functions corresponds to standard library allocator concepts and definitions. The current implementation supports C++11 standard.

Template arguments:\
 *T* is an object type aliased by value\_type.\
 *U* is an object type.

**Note:**\
 **T \*libmemkind::pmem::allocator\<T\>::allocate(std::size\_t** *n***)** allocates persistent memory using **memkind\_malloc**(). Throw *std::bad\_alloc* when:\

*n* = 0

or there is not enough memory to satisfy the request.

**libmemkind::pmem::allocator\<T\>::deallocate(T** *\*p***, std::size\_t** *n***)** deallocates memory associated with pointer returned by **allocate**() using **memkind\_free**().

## COPYRIGHT

Copyright (C) 2018 - 2021 Intel Corporation. All rights reserved.

## SEE ALSO

[**memkind\_pmem**(3)](/memkind_pmem/3.md), [**memkind**(3)](/memkind/3.md)
