aboutsummaryrefslogtreecommitdiff
path: root/src/leveldb.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/leveldb.cpp')
-rw-r--r--src/leveldb.cpp12
1 files changed, 9 insertions, 3 deletions
diff --git a/src/leveldb.cpp b/src/leveldb.cpp
index 29e5e6a7fd..e8a0fbe874 100644
--- a/src/leveldb.cpp
+++ b/src/leveldb.cpp
@@ -8,6 +8,7 @@
#include <leveldb/env.h>
#include <leveldb/cache.h>
#include <leveldb/filter_policy.h>
+#include <memenv/memenv.h>
#include <boost/filesystem.hpp>
@@ -20,7 +21,7 @@ static leveldb::Options GetOptions() {
return options;
}
-CLevelDB::CLevelDB(const boost::filesystem::path &path) {
+CLevelDB::CLevelDB(const boost::filesystem::path &path, bool fMemory) {
penv = NULL;
readoptions.verify_checksums = true;
iteroptions.verify_checksums = true;
@@ -28,8 +29,13 @@ CLevelDB::CLevelDB(const boost::filesystem::path &path) {
syncoptions.sync = true;
options = GetOptions();
options.create_if_missing = true;
- boost::filesystem::create_directory(path);
- printf("Opening LevelDB in %s\n", path.string().c_str());
+ if (fMemory) {
+ penv = leveldb::NewMemEnv(leveldb::Env::Default());
+ options.env = penv;
+ } else {
+ boost::filesystem::create_directory(path);
+ printf("Opening LevelDB in %s\n", path.string().c_str());
+ }
leveldb::Status status = leveldb::DB::Open(options, path.string(), &pdb);
if (!status.ok())
throw std::runtime_error(strprintf("CLevelDB(): error opening database environment %s", status.ToString().c_str()));