#include <fcntl.h>
#include <libpmemobj++/make_persistent.hpp>
#include <libpmemobj++/p.hpp>
#include <libpmemobj++/persistent_ptr.hpp>
#include <libpmemobj++/pool.hpp>
#include <libpmemobj++/transaction.hpp>
using namespace pmem::obj;
void
make_persistent_example()
{
struct compound_type {
compound_type(int val, double dval)
: some_variable(val), some_other_variable(dval)
{
}
void
set_some_variable(int val)
{
some_variable = val;
}
p<int> some_variable;
p<double> some_other_variable;
};
struct root {
persistent_ptr<compound_type> comp; };
auto pop = pool<root>::create("poolfile", "layout", PMEMOBJ_MIN_POOL);
auto proot = pop.get_root();
transaction::exec_tx(pop, [&] {
proot->comp = make_persistent<compound_type>(1, 2.0);
delete_persistent<compound_type>(proot->comp);
});
auto arr1 = make_persistent<compound_type>(2, 15.0);
delete_persistent<compound_type>(arr1);
}
#include <fcntl.h>
#include <libpmemobj++/make_persistent_array.hpp>
#include <libpmemobj++/p.hpp>
#include <libpmemobj++/persistent_ptr.hpp>
#include <libpmemobj++/pool.hpp>
#include <libpmemobj++/transaction.hpp>
using namespace pmem::obj;
void
make_persistent_array_example()
{
struct compound_type {
compound_type() : some_variable(0), some_other_variable(0)
{
}
void
set_some_variable(int val)
{
some_variable = val;
}
p<int> some_variable;
p<double> some_other_variable;
};
struct root {
persistent_ptr<compound_type[]> comp; };
auto pop = pool<root>::create("poolfile", "layout", PMEMOBJ_MIN_POOL);
auto proot = pop.get_root();
transaction::exec_tx(pop, [&] {
proot->comp = make_persistent<compound_type[]>(20);
auto arr1 = make_persistent<compound_type[3]>();
delete_persistent<compound_type[]>(proot->comp, 20);
delete_persistent<compound_type[3]>(arr1);
});
auto arr1 = make_persistent<compound_type[3]>();
delete_persistent<compound_type[3]>(arr1);
}
#include <fcntl.h>
#include <libpmemobj++/make_persistent_atomic.hpp>
#include <libpmemobj++/p.hpp>
#include <libpmemobj++/persistent_ptr.hpp>
#include <libpmemobj++/pool.hpp>
#include <libpmemobj++/transaction.hpp>
using namespace pmem::obj;
void
make_persistent_atomic_example()
{
struct compound_type {
compound_type(int val, double dval)
: some_variable(val), some_other_variable(dval)
{
}
void
set_some_variable(int val)
{
some_variable = val;
}
p<int> some_variable;
p<double> some_other_variable;
};
struct root {
persistent_ptr<compound_type> comp; };
auto pop = pool<root>::create("poolfile", "layout", PMEMOBJ_MIN_POOL);
auto proot = pop.get_root();
make_persistent_atomic<compound_type>(pop, proot->comp, 1, 2.0);
delete_persistent<compound_type>(proot->comp);
transaction::exec_tx(pop, [&] {
make_persistent_atomic<compound_type>(pop, proot->comp, 1, 1.3);
delete_persistent_atomic<compound_type>(proot->comp);
});
}
#include <fcntl.h>
#include <libpmemobj++/make_persistent_array_atomic.hpp>
#include <libpmemobj++/p.hpp>
#include <libpmemobj++/persistent_ptr.hpp>
#include <libpmemobj++/pool.hpp>
#include <libpmemobj++/transaction.hpp>
using namespace pmem::obj;
void
make_persistent_array_atomic_example()
{
struct compound_type {
compound_type() : some_variable(0), some_other_variable(0)
{
}
void
set_some_variable(int val)
{
some_variable = val;
}
p<int> some_variable;
p<double> some_other_variable;
};
struct root {
persistent_ptr<compound_type[]> comp; };
auto pop = pool<root>::create("poolfile", "layout", PMEMOBJ_MIN_POOL);
auto proot = pop.get_root();
make_persistent_atomic<compound_type[]>(pop, proot->comp, 20);
persistent_ptr<compound_type[42]> arr;
make_persistent_atomic<compound_type[42]>(pop, arr);
delete_persistent_atomic<compound_type[]>(proot->comp, 20);
delete_persistent_atomic<compound_type[42]>(arr);
transaction::exec_tx(pop, [&] {
make_persistent_atomic<compound_type[]>(pop, proot->comp, 30);
delete_persistent_atomic<compound_type[]>(proot->comp, 30);
});
}