112
This chapter describes how to leverage the C++ language features that support
metaprogramming to make persistent memory programming easier. It also describes
how to make it more C++ idiomatic by providing persistent containers. Finally, we
discuss C++ standard limitations for persistent memory programming, including an
object’s lifetime and the internal layout of objects stored in persistent memory.
Metaprogramming to the Rescue
Metaprogramming is a technique in which computer programs have the ability to treat
other programs as their data. It means that a program can be designed to read, generate,
analyze or transform other programs, and even modify itself while running. In some
cases, this allows programmers to minimize the number of lines of code to express a
solution, in turn reducing development time. It also allows programs greater flexibility to
efficiently handle new situations without recompilation.
For the libpmemobj-cpp library, considerable effort was put into encapsulating
the PMEMoids (persistent memory object IDs) with a type-safe container. Instead of a
sophisticated set of macros for providing type safety, templates and metaprogramming
are used. This significantly simplifies the native C libpmemobj API.
Persistent Pointers
The persistent memory programming model created by the Storage Networking Industry
Association (SNIA) is based on memory-mapped files. PMDK uses this model for its
architecture and design implementation. We discussed the SNIA programming model in
Chapter 3.
Most operating systems implement address space layout randomization (ASLR).
ASLR is a computer security technique involved in preventing exploitation of memory
corruption vulnerabilities. To prevent an attacker from reliably jumping to, for example,
a particular exploited function in memory, ASLR randomly arranges the address space
positions of key data areas of a process, including the base of the executable and the
positions of the stack, heap, and libraries. Because of ASLR, files can be mapped at
different addresses of the process address space each time the application executes.
As a result, traditional pointers that store absolute addresses cannot be used. Upon
each execution, a traditional pointer might point to uninitialized memory for which
Chapter 8 libpmemobj-Cpp: the adaptable language - C++ and persistent memory
Précédent

- 138/457

Suivant