|
| defrag (pool_base p) |
| The only allowed ctor. More...
|
|
template<typename T > |
std::enable_if< is_defragmentable< T >), void >::type | add (T &t) |
| Stores address of the referenced object to the defragmentation queue. More...
|
|
template<typename T , typename = T> |
std::enable_if<!is_defragmentable< T >), void >::type | add (T &t) |
| Specialization for non-defragmentable types. More...
|
|
template<typename T > |
void | add (persistent_ptr< T > &ptr) |
| Stores address of a persistent_ptr to the defragmentation queue. More...
|
|
pobj_defrag_result | run () |
| Starts defragmentation with previously stored pointers. More...
|
|
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.
Important note: an instance of this class can collect pointers only from one pmem::obj::pool instance.
The typical usage example would be:
#include <libpmemobj/atomic_base.h>
void
defrag_example()
{
struct root {
};
auto r = pop.root();
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;
}
template<typename T , typename = T>
std::enable_if<!is_defragmentable<T>), void>::type pmem::obj::defrag::add |
( |
T & |
t | ) |
|
|
inline |
Specialization for non-defragmentable types.
It's to be called on (most likely trivial) types, which are NOT defragmentable - it means they don't implement 'for_each_ptr' method.
Thanks to this specialization there's no need to check for each object, if it's defragmentable, before calling 'add()'.
- Parameters
-
[in] | t | object of type T to be added to the defragmentation queue. |
- Exceptions
-
std::runtime_error | when object t is not from the pool passed in ctor. |