172
42 #include
43
44 typedef libmemkind::pmem::allocator str_alloc_type;
45
46 typedef std::basic_string,
str_alloc_type> pmem_string;
47
48 typedef libmemkind::pmem::allocator vec_alloc_type;
49
50 typedef std::vector > vector_type;
51
52 int main(int argc, char *argv[]) {
53
const size_t pmem_max_size = 64 * 1024 * 1024; //64 MB
54
const std::string pmem_dir("/daxfs");
55
56
// Create allocator object
57
vec_alloc_type alc(pmem_dir, pmem_max_size);
58
// Create std::vector with our allocator.
59
vector_type v(alc);
60
61
v.emplace_back("Foo");
62
v.emplace_back("Bar");
63
64
for (auto str : v) {
65
std::cout << str << std::endl;
66
}
• Line 46: We define pmem_string as a typedef of std::basic_string.
• Line 48: We define the pmem::allocator using the pmem_string type.
• Line 50: Using std::scoped_allocator_adaptor allows the vector to
propagate the pmem::allocator instance to all pmem_string objects
stored in the vector object.
Chapter 10 Volatile Use of persistent MeMory
Précédent

- 196/457

Suivant