TX_FREE(3)
pmemobj_tx_alloc(3) β transactional object manipulation π β¨
PMDK Programmer's Manual
okay bestie, sit down, hydrate, because this is the page where all your transactional memory dreams live. it's giving "allocate, resize, duplicate, free β but make it atomic." π¦
β¨ NAME β¨
pmemobj_tx_alloc(), pmemobj_tx_zalloc(), pmemobj_tx_xalloc(), pmemobj_tx_realloc(), pmemobj_tx_zrealloc(), pmemobj_tx_strdup(), pmemobj_tx_xstrdup(), pmemobj_tx_wcsdup(), pmemobj_tx_xwcsdup(), pmemobj_tx_free(), pmemobj_tx_xfree()
TX_NEW(), TX_ALLOC(), TX_ZNEW(), TX_ZALLOC(), TX_XALLOC(), TX_REALLOC(), TX_ZREALLOC(), TX_STRDUP(), TX_XSTRDUP(), TX_WCSDUP(), TX_XWCSDUP(), TX_FREE(), TX_XFREE() β transactional object manipulation πΈ
β¨ SYNOPSIS β¨
#include <libpmemobj.h>
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_xalloc(size_t size, uint64_t type_num, uint64_t flags);
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);
int pmemobj_tx_free(PMEMoid oid);
int pmemobj_tx_xfree(PMEMoid oid, uint64_t flags);
TX_NEW(TYPE)
TX_ALLOC(TYPE, size_t size)
TX_ZNEW(TYPE)
TX_ZALLOC(TYPE, size_t size)
TX_XALLOC(TYPE, size_t size, uint64_t flags)
TX_REALLOC(TOID o, size_t size)
TX_ZREALLOC(TOID o, size_t size)
TX_STRDUP(const char *s, uint64_t type_num)
TX_WCSDUP(const wchar_t *s, uint64_t type_num)
TX_FREE(TOID o)
TX_XFREE(TOID o, uint64_t flags)
β¨ DESCRIPTION β¨
π the plain functions (no macros, just vibes)
pmemobj_tx_alloc() transactionally allocates a brand new object of the given size and type_num. here's the β¨special sauceβ¨ that separates it from the non-transactional allocations: the objects only get added to the internal object containers of the given type_num after the transaction is committed, which is what makes them visible to the POBJ_FOREACH_*() macros. no cap. this function must be called during TX_STAGE_WORK. π
pmemobj_tx_zalloc() transactionally allocates a new zeroed object of the given size and type_num. yes, zeroed. pristine. untouched. must be called during TX_STAGE_WORK. π§
pmemobj_tx_xalloc() transactionally allocates a new object of the given size and type_num. the flags argument is a bitmask, and here's what you can put in it:
POBJ_XALLOC_ZEROβ zero the allocated object (it's the equivalent ofpmemobj_tx_zalloc, so basically the glow-up version)POBJ_XALLOC_NO_FLUSHβ skip flush on commit (do this when your application handles the flushing itself, or when it usespmemobj_memcpy_persist)POBJ_CLASS_ID(class_id)β allocate an object from the allocation class with id equal toclass_idPOBJ_ARENA_ID(arena_id)β allocate an object from the arena specified byarena_id. the arena must exist, otherwise the behavior is undefined (!!). ifarena_idis equal0, then the arena assigned to the current thread will be used.POBJ_XALLOC_NO_ABORTβ if the function does not end successfully, do not abort the transaction.
this function must be called during TX_STAGE_WORK. π
pmemobj_tx_realloc() transactionally resizes an existing object to the given size and changes its type to type_num. a couple of gotchas to keep in your notes app:
- if
oidisOID_NULL, then the call is equivalent topmemobj_tx_alloc(pop, size, type_num). - if
sizeis equal to zero andoidis notOID_NULL, then the call is equivalent topmemobj_tx_free(oid). - if the new size is larger than the old size, the added memory will not be initialized. (so it's giving chaos unless you handle it π)
this function must be called during TX_STAGE_WORK. π
pmemobj_tx_zrealloc() transactionally resizes an existing object to the given size and changes its type to type_num. if the new size is larger than the old size, the extended new space is zeroed β that's the difference, that's the "z", bestie. must be called during TX_STAGE_WORK. β¨
pmemobj_tx_strdup() transactionally allocates a new object containing a duplicate of the string s and assigns it a type type_num. must be called during TX_STAGE_WORK. π
pmemobj_tx_xstrdup() behaves exactly the same as pmemobj_tx_strdup() when flags equals zero. the flags argument is a bitmask of values described in the pmemobj_tx_xalloc section above. π
pmemobj_tx_wcsdup() transactionally allocates a new object containing a duplicate of the wide character string s and assigns it a type type_num. must be called during TX_STAGE_WORK. π
pmemobj_tx_xwcsdup() behaves exactly the same as pmemobj_tx_wcsdup() when flags equals zero. the flags argument is a bitmask of values described in the pmemobj_tx_xalloc section above. π
pmemobj_tx_free() transactionally frees an existing object referenced by oid. must be called during TX_STAGE_WORK. π¦
pmemobj_tx_xfree() behaves exactly the same as pmemobj_tx_free() when flags equals zero. flags is a bitmask of the following value:
POBJ_XFREE_NO_ABORTβ if the function does not end successfully, do not abort the transaction.
this function must be called during TX_STAGE_WORK. π
π¦ the macros (the shortcuts your fave devs actually type)
TX_NEW() macro transactionally allocates a new object of the given TYPE and assigns it a type number read from the typed OID. the allocation size is determined from the size of the user-defined structure TYPE. if it's successful and called during TX_STAGE_WORK, it returns a handle to the newly allocated object. otherwise, the stage is changed to TX_STAGE_ONABORT, OID_NULL is returned, and errno is set appropriately. π
TX_ALLOC() macro transactionally allocates a new object of the given TYPE and assigns it a type number read from the typed OID. the allocation size is passed by the size parameter. if successful and called during TX_STAGE_WORK, it returns a handle to the newly allocated object. otherwise, the stage is set to TX_STAGE_ONABORT, OID_NULL is returned, and errno is set appropriately. π
TX_ZNEW() macro transactionally allocates a new zeroed object of the given TYPE and assigns it a type number read from the typed OID. the allocation size is determined from the size of the user-defined structure TYPE. if successful and called during TX_STAGE_WORK, it returns a handle to the newly allocated object. otherwise, the stage changes to TX_STAGE_ONABORT, OID_NULL is returned, and errno is set appropriately. β¨
TX_ZALLOC() macro transactionally allocates a new zeroed object of the given TYPE and assigns it a type number read from the typed OID. the allocation size is passed by the size argument. if successful and called during TX_STAGE_WORK, it returns a handle to the newly allocated object. otherwise, the stage is changed to TX_STAGE_ONABORT, OID_NULL is returned, and errno is set appropriately. π§
TX_XALLOC() macro transactionally allocates a new object of the given TYPE and assigns it a type number read from the typed OID. the allocation size is passed by the size argument. the flags argument is a bitmask of values described in the pmemobj_tx_xalloc section. if successful and called during TX_STAGE_WORK, it returns a handle to the newly allocated object. otherwise, OID_NULL is returned, errno is set, and when flags do not contain POBJ_XALLOC_NO_ABORT, the transaction is aborted. π
TX_REALLOC() macro transactionally resizes an existing object referenced by a handle o to the given size. if successful and called during TX_STAGE_WORK, it returns a handle to the reallocated object. otherwise, the stage is changed to TX_STAGE_ONABORT, OID_NULL is returned, and errno is set appropriately. πΈ
TX_ZREALLOC() macro transactionally resizes an existing object referenced by a handle o to the given size. if the new size is larger than the old size, the extended new space is zeroed. if successful and called during TX_STAGE_WORK, it returns a handle to the reallocated object. otherwise, the stage is changed to TX_STAGE_ONABORT, OID_NULL is returned, and errno is set appropriately. β¨
TX_STRDUP() macro transactionally allocates a new object containing a duplicate of the string s and assigns it type type_num. if successful and called during TX_STAGE_WORK, it returns a handle to the newly allocated object. otherwise, the stage is changed to TX_STAGE_ONABORT, OID_NULL is returned, and errno is set appropriately. π
TX_XSTRDUP() macro transactionally allocates a new object containing a duplicate of the string s and assigns it type type_num. the flags argument is a bitmask of values described in the pmemobj_tx_xalloc section. if successful and called during TX_STAGE_WORK, it returns a handle to the newly allocated object. otherwise, OID_NULL is returned, errno is set, and when flags do not contain POBJ_XALLOC_NO_ABORT, the transaction is aborted. π
TX_WCSDUP() macro transactionally allocates a new object containing a duplicate of the wide character string s and assigns it a type type_num. if successful and called during TX_STAGE_WORK, it returns a handle to the newly allocated object. otherwise, the stage is changed to TX_STAGE_ONABORT, OID_NULL is returned, and errno is set appropriately. π
TX_XWCSDUP() macro transactionally allocates a new object containing a duplicate of the wide character string s and assigns it a type type_num. the flags argument is a bitmask of values described in the pmemobj_tx_xalloc section. if successful and called during TX_STAGE_WORK, it returns a handle to the newly allocated object. otherwise, OID_NULL is returned, errno is set, and when flags do not contain POBJ_XALLOC_NO_ABORT, the transaction is aborted. π
TX_FREE() macro transactionally frees the memory space represented by an object handle o. if o is OID_NULL, no operation is performed. if successful and called during TX_STAGE_WORK, TX_FREE() returns 0. otherwise, the stage is changed to TX_STAGE_ONABORT and errno is set appropriately. π¦
TX_XFREE() macro transactionally frees the memory space represented by an object handle o. if o is OID_NULL, no operation is performed. the flags argument is a bitmask of values described in the pmemobj_tx_xfree section. if successful and called during TX_STAGE_WORK, TX_FREE() returns 0. otherwise, the error number is returned, errno is set, and when flags do not contain POBJ_XFREE_NO_ABORT, the transaction is aborted. π
okay that's the whole front half, bestie β more parts are coming so don't you dare close the tab π
π RETURN VALUE π
okay bestie, here's the tea on what these functions hand back to you π«Ά
β¨ the regular alloc crew β¨
pmemobj_tx_alloc(),pmemobj_tx_zalloc(),pmemobj_tx_strdup(),pmemobj_tx_wcsdup()β when they slay (success π ), they hand you back a handle to the brand-new object you just made. when they don't slay, the stage gets switched toTX_STAGE_ONABORT, you getOID_NULLback, anderrnogets set to something appropriate. and ifsizeequals0?? yeah you getOID_NULLanderrnoset appropriately. no object for you, sorry babe π
β¨ the x-tra special alloc crew β¨
pmemobj_tx_xalloc(),pmemobj_tx_xstrdup(),pmemobj_tx_xwcsdup()β success means a handle to the shiny new object, periodt π. but if things go sideways, you getOID_NULL,errnois set, and β here's the important bit β whenflagsdo not containPOBJ_XALLOC_NO_ABORT, the whole transaction gets aborted. so like, the x versions are out here catching strays, not aborting unless you didn't ask them not to π«
πΈ the realloc girlies πΈ
pmemobj_tx_realloc()andpmemobj_tx_zrealloc()β on success they return a handle to the resized object, iconic. otherwise the stage changes toTX_STAGE_ONABORT,OID_NULLis returned, anderrnois set appropriately.
π¨ bestie WARNING π¨ note that the object handle value may change as a result of reallocation. so like, don't be out here holding onto the old handle like it's your emotional support OID, because it might not be the same one anymore. the way that reallocation just... reshapes your whole life ππ
π freeing the girlies π
pmemobj_tx_free()β on success, returns0. otherwise the stage changes toTX_STAGE_ONABORT,errnois set appropriately, and the transaction is aborted. she's dramatic like that πpmemobj_tx_xfree()β on success, returns0. otherwise the error number is returned,errnois set, and whenflagsdo not containPOBJ_XFREE_NO_ABORT, the transaction is aborted. lowkey the same energy but with β¨ options β¨
π SEE ALSO π
like, go read these next, iykyk:
pmemobj_tx_add_range(3)pmemobj_tx_begin(3)libpmemobj(7)- and obviously https://pmem.io β¨π¦
and that's a wrap on this page bestie!! this one's from the PMDK collection, dated 2025-07-24. go forth and allocate responsibly, mwah ππ π
π¦ where this page comes from
- fedora 43: libpmemobj-devel 2.1.0-4.fc43 Β· BSD-3-Clause
- π the page's license: BSD-3-Clause
- Copyright 2017-2019, Intel Corporation
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms