118
54
55
auto r = pop.root();
56
57
pmem::obj::transaction::run(pop, [&]() {
58
r->mdata = pmem::obj::make_persistent(1, 2);
59
});
60
61
pmem::obj::transaction::run(pop, [&]() {
62
pmem::obj::delete_persistent(r->mdata);
63
});
64
pmem::obj::make_persistent_atomic(pop, r->mdata,
2, 3);
65
66
return 0;
67
}
• Line 58: Here, we allocate my_data object transactionally. Parameters
passed to make_persistent will be forwarded to my_data constructor.
Note that assignment to r->mdata will perform a snapshot of old
persistent pointer’s value.
• Line 62: Here, we delete the my_data object. delete_persistent will
call the object’s destructor and free the memory.
• Line 64: We allocate my_data object atomically. Calling this function
cannot be done inside of a transaction.
C++ Standard limitations
The C++ language restrictions and persistent memory programming paradigm imply
serious restrictions on objects which may be stored on persistent memory. Applications
can access persistent memory with memory-mapped files to take advantage of its byte
addressability thanks to libpmemobj and SNIA programming model. No serialization
takes place here, so applications must be able to read and modify directly from the
persistent memory media even after the application was closed and reopened or after a
power failure event.
Chapter 8 libpmemobj-Cpp: the adaptable language - C++ and persistent memory
54
55
auto r = pop.root();
56
57
pmem::obj::transaction::run(pop, [&]() {
58
r->mdata = pmem::obj::make_persistent
59
});
60
61
pmem::obj::transaction::run(pop, [&]() {
62
pmem::obj::delete_persistent
63
});
64
pmem::obj::make_persistent_atomic
2, 3);
65
66
return 0;
67
}
• Line 58: Here, we allocate my_data object transactionally. Parameters
passed to make_persistent will be forwarded to my_data constructor.
Note that assignment to r->mdata will perform a snapshot of old
persistent pointer’s value.
• Line 62: Here, we delete the my_data object. delete_persistent will
call the object’s destructor and free the memory.
• Line 64: We allocate my_data object atomically. Calling this function
cannot be done inside of a transaction.
C++ Standard limitations
The C++ language restrictions and persistent memory programming paradigm imply
serious restrictions on objects which may be stored on persistent memory. Applications
can access persistent memory with memory-mapped files to take advantage of its byte
addressability thanks to libpmemobj and SNIA programming model. No serialization
takes place here, so applications must be able to read and modify directly from the
persistent memory media even after the application was closed and reopened or after a
power failure event.
Chapter 8 libpmemobj-Cpp: the adaptable language - C++ and persistent memory
