.\" Automatically generated by Pandoc 2.2.1 .\" .TH "PMEMOBJ_ROOT" "3" "2019-02-19" "PMDK - pmemobj API version 2.3" "PMDK Programmer's Manual" .hy .\" Copyright 2014-2019, Intel Corporation .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions .\" are met: .\" .\" * Redistributions of source code must retain the above copyright .\" notice, this list of conditions and the following disclaimer. .\" .\" * Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in .\" the documentation and/or other materials provided with the .\" distribution. .\" .\" * Neither the name of the copyright holder nor the names of its .\" contributors may be used to endorse or promote products derived .\" from this software without specific prior written permission. .\" .\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS .\" "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT .\" LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR .\" A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT .\" OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, .\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT .\" LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, .\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY .\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE .\" OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .SH NAME .PP \f[B]pmemobj_root\f[](), \f[B]pmemobj_root_construct\f[]() \f[B]POBJ_ROOT\f[](), \f[B]pmemobj_root_size\f[]() \- root object management .SH SYNOPSIS .IP .nf \f[C] #include\ PMEMoid\ pmemobj_root(PMEMobjpool\ *pop,\ size_t\ size); PMEMoid\ pmemobj_root_construct(PMEMobjpool\ *pop,\ size_t\ size, \ \ \ \ pmemobj_constr\ constructor,\ void\ *arg); POBJ_ROOT(PMEMobjpool\ *pop,\ TYPE) size_t\ pmemobj_root_size(PMEMobjpool\ *pop); \f[] .fi .SH DESCRIPTION .PP The root object of a persistent memory pool is an entry point for all other persistent objects allocated using the \f[B]libpmemobj\f[] API. In other words, every object stored in the persistent memory pool has the root object at the end of its reference path. It may be assumed that for each persistent memory pool the root object always exists, and there is exactly one root object in each pool. .PP The \f[B]pmemobj_root\f[]() function creates or resizes the root object for the persistent memory pool \f[I]pop\f[]. If this is the first call to \f[B]pmemobj_root\f[](), the requested \f[I]size\f[] is greater than zero and the root object does not exist, it is implicitly allocated in a thread\-safe manner, so the function may be called by more than one thread simultaneously (as long as all threads use the identical \f[I]size\f[] value). The size of the root object is guaranteed to be not less than the requested \f[I]size\f[]. If the requested size is larger than the current size, the root object is automatically resized. In such case, the old data is preserved and the extra space is zeroed. If the requested size is equal to or smaller than the current size, the root object remains unchanged. If the requested \f[I]size\f[] is equal to zero, the root object is not allocated. .PP \f[B]pmemobj_root_construct\f[]() performs the same actions as \f[B]pmemobj_root\f[](), but instead of zeroing the newly allocated object a \f[I]constructor\f[] function is called to initialize the object. The constructor is also called on reallocations. .PP The \f[B]POBJ_ROOT\f[]() macro works the same way as the \f[B]pmemobj_root\f[]() function except it returns a typed \f[I]OID\f[] value. .PP The \f[B]pmemobj_root_size\f[]() function returns the current size of the root object associated with the persistent memory pool \f[I]pop\f[]. .SH RETURN VALUE .PP Upon success, \f[B]pmemobj_root\f[]() returns a handle to the root object associated with the persistent memory pool \f[I]pop\f[]. The same root object handle is returned in all the threads. If the requested object size is larger than the maximum allocation size supported for the pool, or if there is not enough free space in the pool to satisfy a reallocation request, \f[B]pmemobj_root\f[]() returns \f[B]OID_NULL\f[] and sets \f[I]errno\f[] to ENOMEM. If the \f[I]size\f[] was equal to zero and the root object has not been allocated, \f[B]pmemobj_root\f[]() returns \f[B]OID_NULL\f[] and sets \f[I]errno\f[] to EINVAL. .PP If the \f[B]pmemobj_root_construct\f[]() constructor fails, the allocation is canceled, \f[B]pmemobj_root_construct\f[]() returns \f[I]OID_NULL\f[], and \f[I]errno\f[] is set to \f[B]ECANCELED\f[]. \f[B]pmemobj_root_size\f[]() can be used in the constructor to check whether this is the first call to the constructor. .PP \f[B]POBJ_ROOT\f[]() returns a typed \f[I]OID\f[] of type \f[I]TYPE\f[] instead of the \f[I]PMEMoid\f[] returned by \f[B]pmemobj_root\f[](). .PP The \f[B]pmemobj_root_size\f[]() function returns the current size of the root object associated with the persistent memory pool \f[I]pop\f[]. The returned size is the largest value requested by any of the earlier \f[B]pmemobj_root\f[]() calls. If the root object has not been allocated yet, \f[B]pmemobj_root_size\f[]() returns 0. .SH SEE ALSO .PP \f[B]libpmemobj\f[](7) and \f[B]\f[]