#include <fcntl.h>
#include <libpmemobj++/p.hpp>
#include <libpmemobj++/pool.hpp>
#include <libpmemobj++/transaction.hpp>
using namespace pmem::obj;
void
p_property_example()
{
struct compound_type {
void
set_some_variable(int val)
{
some_variable = val;
}
int some_variable;
double some_other_variable;
};
static struct root {
p<int> counter; p<compound_type> whoops; } proot;
auto pop = pool<root>::create("poolfile", "layout", PMEMOBJ_MIN_POOL);
transaction::exec_tx(pop, [&] {
proot.counter = 12; proot.whoops.get_rw().set_some_variable(2);
proot.whoops.get_rw().some_other_variable = 3.0;
});
proot.counter = 12;
}
#include <fcntl.h>
#include <libpmemobj++/make_persistent.hpp>
#include <libpmemobj++/persistent_ptr.hpp>
#include <libpmemobj++/pool.hpp>
#include <libpmemobj++/transaction.hpp>
using namespace pmem::obj;
void
persistent_ptr_example()
{
struct compound_type {
void
set_some_variable(int val)
{
some_variable = val;
}
int some_variable;
double some_other_variable;
};
struct root {
persistent_ptr<compound_type> comp;
} proot;
auto pop = pool<root>::create("poolfile", "layout", PMEMOBJ_MIN_POOL);
transaction::exec_tx(pop, [&] {
proot.comp = make_persistent<compound_type>(); proot.comp->set_some_variable(12); proot.comp->some_other_variable = 2.3; });
compound_type tmp = *proot.comp;
(void)tmp;
proot.comp->some_variable = 12;
}