4
97
if (kv->put("key2", "value2") != status::OK) {
98
cerr << db::errormsg() << endl;
99
exit(1);
100
}
101
if (kv->put("key3", "value3") != status::OK) {
102
cerr << db::errormsg() << endl;
103
exit(1);
104
}
105
106
// iterate through the key-value store, printing them
107
kv->get_all(kvprint);
108
109
// stop the pmemkv engine
110
delete kv;
111
112
exit(0);
113 }
• Line 57: We define a small helper routine, kvprint(), which prints a
key-value pair when called.
• Line 63: This is the first line of main() which is where every C++
program begins execution. We start by instantiating a key-value
engine using the engine name "cmap". We discuss other engine types
in Chapter 9.
• Line 70: The cmap engine takes config parameters from a config
structure. The parameter "path" is configured to "/daxfs/kvfile",
which is the path to a persistent memory file on a DAX file system;
the parameter "size" is set to SIZE. Chapter 3 describes how to
create and mount DAX file systems.
• Line 93: We add several key-value pairs to the store. The trademark
of a key-value store is the use of simple operations like put() and
get(); we only show put() in this example.
• Line 107: Using the get_all() method, we iterate through the
entire key-value store, printing each pair when get_all() calls our
kvprint() routine.
CHApter 1 IntroduCtIon to persIstent MeMory proGrAMMInG
Précédent

- 33/457

Suivant