169
The pmem::allocator class template uses the memkind_create_pmem() function
described previously. This allocator is stateful and has no default constructor.
pmem::allocator methods
pmem::allocator(const char *dir, size_t max_size);
pmem::allocator(const std::string& dir, size_t max_size) ;
template pmem::allocator::allocator(const
pmem::allocator&);
template pmem::allocator(allocator&& other);
pmem::allocator::~allocator();
T* pmem::allocator::allocate(std::size_t n) const;
void pmem::allocator::deallocate(T* p, std::size_t n) const ;
template void pmem::allocator::construct(U* p,
Args... args) const;
void pmem::allocator::destroy(T* p) const;
For more information about the pmem::allocator class template, refer to the pmem
allocator(3) man page.
Nested Containers
Multilevel containers such as a vector of lists, tuples, maps, strings, and so on pose
challenges in handling the nested objects.
Imagine you need to create a vector of strings and store it in persistent memory. The
challenges – and their solutions – for this task include:
1. Challenge: The std::string cannot be used for this purpose because
it is an alias of the std::basic_string. The std::allocator requires a
new alias that uses pmem:allocator.
Solution: A new alias called pmem_string is defined as a typedef
of std::basic_string when created with pmem::allocator.
Chapter 10 Volatile Use of persistent MeMory
Précédent

- 193/457

Suivant