2
A High-Level Example Program
To illustrate how persistent memory is used, we start with a sample program
demonstrating the key-value store provided by a library called libpmemkv. Listing 1-1
shows a full C++ program that stores three key-value pairs in persistent memory and
then iterates through the key-value store, printing all the pairs. This example may seem
trivial, but there are several interesting components at work here. Descriptions below the
listing show what the program does.
Listing 1-1. A sample program using libpmemkv
37 #include
38 #include
39 #include
40
41 using namespace pmem::kv;
42 using std::cerr;
43 using std::cout;
44 using std::endl;
45 using std::string;
46
47 /*
48 * for this example, create a 1 Gig file
49 * called "/daxfs/kvfile"
50 */
51 auto PATH = "/daxfs/kvfile";
52 const uint64_t SIZE = 1024 * 1024 * 1024;
53
54 /*
55 * kvprint -- print a single key-value pair
56 */
57 int kvprint(string_view k, string_view v) {
58
cout << "key: "
<< k.data() <<
59
" value: " << v.data() << endl;
60
return 0;
61 }
62
CHApter 1 IntroduCtIon to persIstent MeMory proGrAMMInG
Précédent

- 31/457

Suivant