Hi,
I am trying to create object of a class using "make_persistent<>()", and I am getting transaction_scope_error with message "refusing to allocate memory outside of transaction scope". I can't figure out how to do it. Below I explain the scenario with code snippet:
1. tree.hpp file: In this file, There is a Node class, which has some functions, like insert, search
#include<iostream>
#include<libpmemobj++/p.hpp>
#include<libpmemobj++/pool.hpp>
#include<libpmemobj++/persistent_ptr.hpp>
#include<libpmemobj++/make_persistent_atomic.hpp>
#include <libpmemobj++/transaction.hpp>
#include<libpmemobj++/make_persistent.hpp>
using namespace pmem;
using namespace pmem::obj;
class Node{
private:
//some variables
//some functions
public:
//some variables
//some functions
void insert(int data);
};
2. main.cpp file: In this class, I want to create an object of Node class and want to insert some data into Node.
#include"tree.hpp"
int main(void){
pool<Node>pop;
persistent_ptr<Node>root;
try {
if (file_exist(path) != 0) {
pop = pool<Node>::open(path, LAYOUT);
} else {
pop = pool<Node>::create(path, LAYOUT, POOLSIZE,
S_IWRITE | S_IREAD);
}
root=pop.root();
} catch (const pmem::pool_error &e) {
std::cerr << "Exception: " << e.what() << std::endl;
return;
} catch (const pmem::transaction_error &e) {
std::cerr << "Exception: " << e.what() << std::endl;
return;
}
root=make_persistent<Node>(); // this line 19, throws
root.insert(data); //pmem::transaction_scope_error exception
return 0;
}
when I change line 19 as:
transaction::run(pop,[]{
});