Defrag class.
This class implements methods used to store pointers from a pool. When defragmentation is called/run, all objects previously stored will be a subject of a defragmentation process.
#include <iostream>
#include <libpmemobj/atomic_base.h>
struct root {
persistent_ptr<int> i;
persistent_ptr<vector<int>> v;
persistent_ptr<vector<double>> v2;
};
void
defrag_example(pool<root> &pop)
{
auto r = pop.root();
persistent_ptr<int> i_ptr;
r->i = make_persistent<int>(5);
r->v = make_persistent<vector<int>>();
r->v2 = make_persistent<vector<double>>();
i_ptr = make_persistent<int>(10);
});
r->v->push_back(15);
my_defrag.add(r->i);
my_defrag.add(r->v);
my_defrag.add(*r->v2);
my_defrag.add(i_ptr);
std::cout << is_defragmentable<persistent_ptr<int>>();
static_assert(is_defragmentable<vector<char>>(), "should not assert");
pobj_defrag_result result;
try {
result = my_defrag.run();
std::cerr << e.what() << "No. of the relocated objects: "
<<
" out of total: " << e.
result.total
<< " processed." << std::endl;
}
std::cout << "No. of relocated objects: " << result.relocated
<< " out of total: " << result.total << " processed."
<< std::endl;
}
Custom defrag error class.
Definition: pexceptions.hpp:225
pobj_defrag_result result
Results of the defragmentation run.
Definition: pexceptions.hpp:249
static void run(obj::pool_base &pool, std::function< void()> tx, Locks &... locks)
Execute a closure-like transaction and lock locks.
Definition: transaction.hpp:694
defrag(pool_base p)
The only allowed ctor.
Definition: defrag.hpp:93
Main libpmemobj namespace.
Definition: allocation_flag.hpp:18
Base class for persistent_ptr.
Vector container with std::vector compatible interface.