#!./pmemobjcli -s
# This is an example script for pmemobjcli application.
# usage: ./example.posc <file>

# print root object pointer
pmemobj_direct r

# allocate root object with specified size
pmemobj_root 1024

# print root object pointer after allocation
pmemobj_direct r

# print size of root object
pmemobj_root_size

# print usable size of root object
pmemobj_alloc_usable_size r

# print type number of root object
pmemobj_type_num r

# allocate four zeroed objects in root object
# at positions 0, 1, 2 and 3
pmemobj_alloc r.0 1 8192
pmemobj_zalloc r.1 2 256
pmemobj_zalloc r.2 3 128
pmemobj_zalloc r.3 3 128

# reallocate two objects
pmemobj_realloc r.0 3 2
pmemobj_zrealloc r.0 4 8192

# duplicate 0 pattern in root object
# at positions 4
pmemobj_strdup r.4 0 5

# print pointers of allocated objects
pmemobj_direct r.0
pmemobj_direct r.1

# print type numbers of allocated objects
pmemobj_type_num r.0
pmemobj_type_num r.1

# print usable size of allocated objects
pmemobj_alloc_usable_size r.0
pmemobj_alloc_usable_size r.1

# print first and next element on external list
pmemobj_first
pmemobj_next r.2

# set 0 in root object at positions 2 and 3
pmemobj_memset_persist r.2 0 255 128
pmemobj_memset_persist r.3 0 0 128

# copy 128 bytes from position 2 of root object to
# position 3
pmemobj_memcpy_persist r.3 0 r.2 0 128

# perform pmemobj_persist on root object at position 3
pmemobj_persist r.3 32 96

# perform pmemobj_flush on root object at position 2
pmemobj_flush r.2 32 96

# perform pmemobj_drain on given pool
pmemobj_drain

# print uuid of pool containing root object
pmemobj_pool_by_oid r

# print uuid of pool containing address of
# root object at position 3
pmemobj_pool_by_ptr r.3 32

# zero the first 256 bytes of r.0 and r.1
pmemobj_memset_persist r.0 0 0 256
pmemobj_memset_persist r.1 0 0 256

# allocate and add elements to both lists
pmemobj_memset_persist r.0 0 0 32
pmemobj_list_insert_new r.4 r.0 NULL 1 64 3
pmemobj_list_insert_new r.5 r.1 NULL 1 64 3

# add existing element to first list
pmemobj_list_insert r.3 r.0 r.4 1

# add existing element as a head of second list
pmemobj_list_insert r.2 r.1 NULL 0

# move all elements from first to second list
pmemobj_list_move r.4 r.0 r.1 r.5 0
pmemobj_list_move r.3 r.0 r.1 r.4 0

# remove elements from second list
pmemobj_list_remove r.2 r.1 0
pmemobj_list_remove r.3 r.1 0

# remove and free elements from second list
pmemobj_list_remove r.4 r.1 1
pmemobj_list_remove r.5 r.1 1

# free allocated objects
pmemobj_free r.0
pmemobj_free r.1
pmemobj_free r.2
pmemobj_free r.3

# print pointer of freed object
pmemobj_direct r.0
