146
Listing 9-1. pmemkv_config.h – An example of the pmemkv_config structure
using the C API
1
#include
2
#include
3
#include
4
5
pmemkv_config* config_setup(const char* path, const uint64_t fcreate,
const uint64_t size) {
6
pmemkv_config *cfg = pmemkv_config_new();
7
assert(cfg != nullptr);
8
9
if (pmemkv_config_put_string(cfg, "path", path) != PMEMKV_STATUS_OK) {
10
fprintf(stderr, "%s", pmemkv_errormsg());
11
return NULL;
12
}
13
14
if (pmemkv_config_put_uint64(cfg, "force_create", fcreate) !=
PMEMKV_STATUS_OK) {
15
fprintf(stderr, "%s", pmemkv_errormsg());
16
return NULL;
17
}
18
19
if (pmemkv_config_put_uint64(cfg, "size", size) != PMEMKV_STATUS_OK) {
20
fprintf(stderr, "%s", pmemkv_errormsg());
21
return NULL;
22
}
23
24
return cfg;
25
}
• Line 5: We define custom function to prepare config and set all
required params for engine(s) to use.
• Line 6: We create an instance of C config class. It returns nullptr on
failure.
Chapter 9 pmemkv: a persistent in- memory key-value store
Listing 9-1. pmemkv_config.h – An example of the pmemkv_config structure
using the C API
1
#include
2
#include
3
#include
4
5
pmemkv_config* config_setup(const char* path, const uint64_t fcreate,
const uint64_t size) {
6
pmemkv_config *cfg = pmemkv_config_new();
7
assert(cfg != nullptr);
8
9
if (pmemkv_config_put_string(cfg, "path", path) != PMEMKV_STATUS_OK) {
10
fprintf(stderr, "%s", pmemkv_errormsg());
11
return NULL;
12
}
13
14
if (pmemkv_config_put_uint64(cfg, "force_create", fcreate) !=
PMEMKV_STATUS_OK) {
15
fprintf(stderr, "%s", pmemkv_errormsg());
16
return NULL;
17
}
18
19
if (pmemkv_config_put_uint64(cfg, "size", size) != PMEMKV_STATUS_OK) {
20
fprintf(stderr, "%s", pmemkv_errormsg());
21
return NULL;
22
}
23
24
return cfg;
25
}
• Line 5: We define custom function to prepare config and set all
required params for engine(s) to use.
• Line 6: We create an instance of C config class. It returns nullptr on
failure.
Chapter 9 pmemkv: a persistent in- memory key-value store
