-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstring_store_pmdk.cpp
52 lines (46 loc) · 1.35 KB
/
string_store_pmdk.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
//
// Created by 王柯 on 2021-01-25.
//
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <libpmemobj.h>
using namespace std;
#define LAYOUT_NAME "intro_0"
#define MAXBUFLEN 10
struct my_root {
size_t len;
char buf[MAXBUFLEN];
};
int main(int argc, char *argv[]) {
//argv[1] repersents the pool file
PMEMobjpool *pop = pmemobj_create(argv[1], LAYOUT_NAME, PMEMOBJ_MIN_POOL, 0666);
if (pop == NULL) {
perror("pmemobj_create");
return 1;
}
// PMEMoid root = pmemobj_root(pop, sizeof(struct my_root));
// my_root *rootp = (my_root *) pmemobj_direct(root);
//
char buf[MAXBUFLEN] = {"hello"};
// rootp->len = strlen(buf);
// pmemobj_persist(pop, &rootp->len, sizeof(rootp->len));
// pmemobj_memcpy_persist(pop, rootp->buf, buf, rootp->len);
//
// TX_BEGIN(pop) {
// pmemobj_tx_add_range(root, 0, sizeof(my_root));
// memcpy(rootp->buf, buf, strlen(buf));
// }
// TX_END
POBJ_LAYOUT_BEGIN(string_store);
POBJ_LAYOUT_ROOT(string_store, struct my_root)
POBJ_LAYOUT_END(string_store)
TOID(struct my_root) root = POBJ_ROOT(pop, struct my_root);
TX_BEGIN(pop) {
TX_MEMCPY(D_RW(root)->buf, buf, strlen(buf));
}
TX_END
cout << D_RO(root)->buf << endl;
pmemobj_close(pop);
return 0;
}