86
73
rootp->len = strlen(buf);
74
pmemobj_persist(pop, &rootp->len,
75
sizeof(rootp->len));
76
77
pmemobj_memcpy_persist(pop, rootp->buf, buf,
78
rootp->len);
79
80
pmemobj_close(pop);
81
82
return 0;
83 }
• Line 42: We define the name for our pool layout to be “rweg” (readwrite example). This is just a name and can be any string that
uniquely identifies the pool to the application. A NULL value is valid.
In the case where multiple pools are opened by the application, this
name uniquely identifies it.
• Line 43: We define the maximum length of the write buffer.
• Lines 45-47: This defines the root object data structure which has
members len and buf. buf contains the string we want to write, and
the len is the length of the buffer.
• Lines 53- 56: The pwriter command accepts one argument: the path
and pool name to write to. For example, /mnt/pmemfs0/helloworld_
obj.pool. The file name extension is arbitrary and optional.
• Lines 58-59: We call pmemobj_create() to create the pool using
the file name passed in from the command line, the layout name
of “rweg,” a size we set to be the minimum size for an object pool
type, and permissions of 0666. We cannot create a pool smaller than
defined by PMEMOBJ_MIN_POOL or larger than the available space
on the file system. Since the string in our example is very small, we
only require a minimally sized pool. On success, pmemobj_create()
returns a pool object pointer (POP) of type PMEMobjpool, that we can
use to acquire a pointer to the root object.
Chapter 7 libpmemobj: a Native traNsaCtioNal objeCt store
Précédent

- 113/457

Suivant