94
Persisting Data
The typical intent of using persistent memory is to save data persistently. For this, you
need to use one of three APIs that libpmemobj provides:
• Atomic operations
• Reserve/publish
• Transactional
Atomic Operations
The pmemobj_alloc() and its variants shown below are easy to use, but they are limited
in features, so additional coding is required by the developer:
int pmemobj_alloc(PMEMobjpool *pop, PMEMoid *oidp,
size_t size, uint64_t type_num, pmemobj_constr
constructor, void *arg);
int pmemobj_zalloc(PMEMobjpool *pop, PMEMoid *oidp,
size_t size, uint64_t type_num);
void pmemobj_free(PMEMoid *oidp);
int pmemobj_realloc(PMEMobjpool *pop, PMEMoid *oidp,
size_t size, uint64_t type_num);
int pmemobj_zrealloc(PMEMobjpool *pop, PMEMoid *oidp,
size_t size, uint64_t type_num);
int pmemobj_strdup(PMEMobjpool *pop, PMEMoid *oidp,
const char *s, uint64_t type_num);
int pmemobj_wcsdup(PMEMobjpool *pop, PMEMoid *oidp,
const wchar_t *s, uint64_t type_num);
The TOID-based wrappers for most of these functions include:
POBJ_NEW(PMEMobjpool *pop, TOID *oidp, TYPE,
pmemobj_constr constructor, void *arg)
POBJ_ALLOC(PMEMobjpool *pop, TOID *oidp, TYPE, size_t size,
pmemobj_constr constructor, void *arg)
POBJ_ZNEW(PMEMobjpool *pop, TOID *oidp, TYPE)
POBJ_ZALLOC(PMEMobjpool *pop, TOID *oidp, TYPE, size_t size)
Chapter 7 libpmemobj: a Native traNsaCtioNal objeCt store
Persisting Data
The typical intent of using persistent memory is to save data persistently. For this, you
need to use one of three APIs that libpmemobj provides:
• Atomic operations
• Reserve/publish
• Transactional
Atomic Operations
The pmemobj_alloc() and its variants shown below are easy to use, but they are limited
in features, so additional coding is required by the developer:
int pmemobj_alloc(PMEMobjpool *pop, PMEMoid *oidp,
size_t size, uint64_t type_num, pmemobj_constr
constructor, void *arg);
int pmemobj_zalloc(PMEMobjpool *pop, PMEMoid *oidp,
size_t size, uint64_t type_num);
void pmemobj_free(PMEMoid *oidp);
int pmemobj_realloc(PMEMobjpool *pop, PMEMoid *oidp,
size_t size, uint64_t type_num);
int pmemobj_zrealloc(PMEMobjpool *pop, PMEMoid *oidp,
size_t size, uint64_t type_num);
int pmemobj_strdup(PMEMobjpool *pop, PMEMoid *oidp,
const char *s, uint64_t type_num);
int pmemobj_wcsdup(PMEMobjpool *pop, PMEMoid *oidp,
const wchar_t *s, uint64_t type_num);
The TOID-based wrappers for most of these functions include:
POBJ_NEW(PMEMobjpool *pop, TOID *oidp, TYPE,
pmemobj_constr constructor, void *arg)
POBJ_ALLOC(PMEMobjpool *pop, TOID *oidp, TYPE, size_t size,
pmemobj_constr constructor, void *arg)
POBJ_ZNEW(PMEMobjpool *pop, TOID *oidp, TYPE)
POBJ_ZALLOC(PMEMobjpool *pop, TOID *oidp, TYPE, size_t size)
Chapter 7 libpmemobj: a Native traNsaCtioNal objeCt store
