101
int pmemobj_tx_add_range(PMEMoid oid, uint64_t off,
size_t size);
int pmemobj_tx_add_range_direct(const void *ptr, size_t size);
TX_ADD(TOID o)
TX_ADD_FIELD(TOID o, FIELD)
TX_ADD_DIRECT(TYPE *p)
TX_ADD_FIELD_DIRECT(TYPE *p, FIELD)
TX_SET(TOID o, FIELD, VALUE)
TX_SET_DIRECT(TYPE *p, FIELD, VALUE)
TX_MEMCPY(void *dest, const void *src, size_t num)
TX_MEMSET(void *dest, int c, size_t num)
The transaction may also allocate entirely new objects, reserve their memory, and
then persistently allocate them only one transaction commit. These functions include
PMEMoid pmemobj_tx_alloc(size_t size, uint64_t type_num);
PMEMoid pmemobj_tx_zalloc(size_t size, uint64_t type_num);
PMEMoid pmemobj_tx_realloc(PMEMoid oid, size_t size,
uint64_t type_num);
PMEMoid pmemobj_tx_zrealloc(PMEMoid oid, size_t size,
uint64_t type_num);
PMEMoid pmemobj_tx_strdup(const char *s, uint64_t type_num);
PMEMoid pmemobj_tx_wcsdup(const wchar_t *s,
uint64_t type_num);
We can rewrite the banking example from Listing 7-6 using the transaction API. Most
of the code remains the same except when we want to add or subtract amounts from the
balance; we encapsulate those updates in a transaction, as shown in Listing 7-7.
Listing 7-7. Using the transaction API to modify bank account balances
33 /*
34 * tx.c - An example using the transaction API
35 */
36
..
Chapter 7 libpmemobj: a Native traNsaCtioNal objeCt store
int pmemobj_tx_add_range(PMEMoid oid, uint64_t off,
size_t size);
int pmemobj_tx_add_range_direct(const void *ptr, size_t size);
TX_ADD(TOID o)
TX_ADD_FIELD(TOID o, FIELD)
TX_ADD_DIRECT(TYPE *p)
TX_ADD_FIELD_DIRECT(TYPE *p, FIELD)
TX_SET(TOID o, FIELD, VALUE)
TX_SET_DIRECT(TYPE *p, FIELD, VALUE)
TX_MEMCPY(void *dest, const void *src, size_t num)
TX_MEMSET(void *dest, int c, size_t num)
The transaction may also allocate entirely new objects, reserve their memory, and
then persistently allocate them only one transaction commit. These functions include
PMEMoid pmemobj_tx_alloc(size_t size, uint64_t type_num);
PMEMoid pmemobj_tx_zalloc(size_t size, uint64_t type_num);
PMEMoid pmemobj_tx_realloc(PMEMoid oid, size_t size,
uint64_t type_num);
PMEMoid pmemobj_tx_zrealloc(PMEMoid oid, size_t size,
uint64_t type_num);
PMEMoid pmemobj_tx_strdup(const char *s, uint64_t type_num);
PMEMoid pmemobj_tx_wcsdup(const wchar_t *s,
uint64_t type_num);
We can rewrite the banking example from Listing 7-6 using the transaction API. Most
of the code remains the same except when we want to add or subtract amounts from the
balance; we encapsulate those updates in a transaction, as shown in Listing 7-7.
Listing 7-7. Using the transaction API to modify bank account balances
33 /*
34 * tx.c - An example using the transaction API
35 */
36
..
Chapter 7 libpmemobj: a Native traNsaCtioNal objeCt store
