mirror of
https://github.com/lucaspalomodevelop/meshlab.git
synced 2026-03-20 11:26:11 +00:00
ongoing berkeleyDB removal
This commit is contained in:
parent
172384d8d9
commit
6409e9e64d
@ -1,222 +0,0 @@
|
||||
|
||||
#ifndef _CHAIN_MEM_BERKELEYDB_
|
||||
#define _CHAIN_MEM_BERKELEYDB_
|
||||
|
||||
|
||||
#ifndef NO_BERKELEY
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <cstdlib>
|
||||
|
||||
#include "berkeleyDb.hpp"
|
||||
#include "../ooc_vector/ooc_chains.h"
|
||||
#include "../../utils/timing.h"
|
||||
|
||||
|
||||
template <class TYPE> int Chain<TYPE>::
|
||||
SaveChunk( typename Chain<TYPE>::Chunk & ck ){
|
||||
TIM::Begin(13);
|
||||
unsigned char * local_buffer = 0;
|
||||
|
||||
if(ck.savedOnce && this->saveOnce) return 0 ;
|
||||
|
||||
RAssert(MemDbg::CheckHeap(0));
|
||||
|
||||
const unsigned int & chunk_order = &ck-&(*chunks.begin());
|
||||
std::string & name = this->GetKey(chunk_order);
|
||||
Dbt key((void*)name.c_str(), (u_int32_t)strlen(name.c_str()) + 1);
|
||||
|
||||
unsigned int siz = ck.Write(local_buffer);
|
||||
Dbt data(local_buffer, siz); data.set_flags(DB_DBT_USERMEM);
|
||||
((BerkeleyDb*)extMemHnd)->getDb().put(NULL, &key, &data, 0);
|
||||
ck.Written(local_buffer);
|
||||
|
||||
if(ck.size == this->params.chunkSize )
|
||||
ck.savedOnce = true;
|
||||
|
||||
TIM::End(13);
|
||||
|
||||
return ck.SizeOfMem();
|
||||
}
|
||||
|
||||
template <class TYPE> void Chain<TYPE>::
|
||||
RemoveChunk( typename Chain<TYPE>::Chunk & ck ){
|
||||
RAssert(MemDbg::CheckHeap(0));
|
||||
const unsigned int & chunk_order = &ck-&(*chunks.begin());
|
||||
std::string & name = this->GetKey(chunk_order);
|
||||
|
||||
Dbt key((void*)name.c_str(), (u_int32_t)strlen(name.c_str()) + 1);
|
||||
((BerkeleyDb*)extMemHnd)->getDb().del(NULL, &key, 0);
|
||||
}
|
||||
|
||||
|
||||
template <class TYPE> void Chain<TYPE>::
|
||||
FetchChunk( typename Chain<TYPE>::Chunk & ck ){
|
||||
RAssert(MemDbg::CheckHeap(1));
|
||||
TIM::Begin(12);
|
||||
|
||||
|
||||
const unsigned int & chunk_order = &ck-&(*chunks.begin());
|
||||
std::string & name = this->GetKey(chunk_order);
|
||||
|
||||
Dbt key((void*)name.c_str(), (u_int32_t)strlen(name.c_str()) + 1);
|
||||
|
||||
|
||||
unsigned char * local_buffer;
|
||||
|
||||
ck.AllocMem(local_buffer);
|
||||
|
||||
Dbt data(local_buffer , ck.SizeOfDisk());
|
||||
|
||||
data.set_flags(DB_DBT_USERMEM);
|
||||
|
||||
data.set_ulen(ck.SizeOfDisk());
|
||||
int res = ((BerkeleyDb*)extMemHnd)->getDb().get(NULL, &key, &data, 0);
|
||||
if(res != 0)
|
||||
printf("record not found");
|
||||
|
||||
ck.Read(local_buffer);
|
||||
|
||||
TIM::End(12);
|
||||
|
||||
}
|
||||
|
||||
template <class TYPE> void Chain<TYPE>::
|
||||
LoadAll(){
|
||||
incore.resize(this->Size());
|
||||
for(unsigned int ci = 0; ci < chunks.size(); ++ci)
|
||||
{
|
||||
typename Chain<TYPE>::Chunk & ck = chunks[ci];
|
||||
unsigned char * ptr = (unsigned char*) &this->incore[ci*this->params.chunkSize];
|
||||
if(ck.buffer){
|
||||
memcpy(ptr,ck.buffer,sizeof(TYPE)*ck.size);
|
||||
}else
|
||||
{
|
||||
RAssert(MemDbg::CheckHeap(1));
|
||||
|
||||
unsigned char * local_buffer = NULL;
|
||||
const unsigned int & chunk_order = &ck-&(*chunks.begin());
|
||||
std::string & name = this->GetKey(chunk_order);
|
||||
Dbt key((void*)name.c_str(), (u_int32_t)strlen(name.c_str()) + 1);
|
||||
|
||||
ck.AllocMem(local_buffer,ptr);
|
||||
|
||||
Dbt data(local_buffer , ck.SizeOfDisk());
|
||||
data.set_flags(DB_DBT_USERMEM);
|
||||
|
||||
data.set_ulen(ck.SizeOfDisk());
|
||||
int res = ((BerkeleyDb*)extMemHnd)->getDb().get(NULL, &key, &data, 0);
|
||||
RAssert(res==0);
|
||||
|
||||
ck.Read(local_buffer,ptr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#else
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <cstdlib>
|
||||
|
||||
#include "berkeleyDb.hpp"
|
||||
#include "../chain_mem.h"
|
||||
|
||||
extern SimpleDb * simpledb;
|
||||
|
||||
template < class HandleChunkType>
|
||||
void OOCEnv< HandleChunkType>::
|
||||
Create( const char * name ){
|
||||
simpledb = new SimpleDb(std::string(""), std::string(name),true);
|
||||
}
|
||||
|
||||
template < typename HandleChunkType>
|
||||
void OOCEnv< HandleChunkType>::
|
||||
Open( const char * name ){
|
||||
simpledb = new SimpleDb(std::string(""), std::string(name),false);
|
||||
}
|
||||
|
||||
|
||||
template < typename HandleChunkType>
|
||||
void OOCEnv< HandleChunkType>::
|
||||
Close( bool andsave){
|
||||
if(andsave){
|
||||
SaveAT();
|
||||
SaveData();
|
||||
}
|
||||
delete simpledb;
|
||||
}
|
||||
|
||||
|
||||
template <class TYPE> void Chain<TYPE>::
|
||||
SaveChunk( typename Chain<TYPE>::Chunk & ck ){
|
||||
RAssert(ck.IsLoaded());
|
||||
simpledb->SaveSegment(ck.handle.key,(char*)ck.buffer,sizeof(TYPE)*ck.capacity);
|
||||
}
|
||||
|
||||
template <class TYPE> void Chain<TYPE>::
|
||||
RemoveChunk( typename Chain<TYPE>::Chunk & ck ){
|
||||
RAssert(MemDbg::CheckHeap(0));
|
||||
/* NOT IMPLEMENTED */
|
||||
}
|
||||
|
||||
template <class TYPE> void Chain<TYPE>::
|
||||
FetchChunk( typename Chain<TYPE>::Chunk & ck ){
|
||||
RAssert(MemDbg::CheckHeap(1));
|
||||
ck.buffer = new TYPE[ck.capacity];
|
||||
lgn->chunks_mem+=sizeof(TYPE)*ck.capacity;
|
||||
simpledb->LoadSegment(ck.handle.key.c_str(), (char*)ck.buffer);
|
||||
}
|
||||
|
||||
template < typename HandleChunkType>
|
||||
void OOCEnv< HandleChunkType>::
|
||||
SaveAT( ){
|
||||
|
||||
int siz = this->SizeOf(); // size of the Allocation Table
|
||||
char * buf = new char[siz]; // allocate memory
|
||||
#ifdef _DEBUG
|
||||
char * res =
|
||||
#endif
|
||||
this->Serialize(buf); // serialize
|
||||
#ifdef _DEBUG
|
||||
RAssert(res-buf == siz);
|
||||
#endif
|
||||
|
||||
char title[65];
|
||||
sprintf(&title[0],"%s","CHAINMEM_ALLOCATION_TABLE");
|
||||
|
||||
|
||||
#ifdef _DEBUG
|
||||
int result =
|
||||
#endif
|
||||
simpledb->SaveSegment(std::string(title), buf,siz);
|
||||
delete buf;
|
||||
#ifdef _DEBUG
|
||||
RAssert(result==0);
|
||||
#endif
|
||||
}
|
||||
|
||||
template < typename HandleChunkType>
|
||||
void OOCEnv< HandleChunkType>::
|
||||
LoadAT( ){
|
||||
char title[65];
|
||||
int size;
|
||||
sprintf(&title[0],"%s","CHAINMEM_ALLOCATION_TABLE");
|
||||
char * buf = new char[simpledb->SizeSegment(std::string(title))];
|
||||
|
||||
simpledb->LoadSegment(std::string(title), buf);
|
||||
#ifdef _DEBUG
|
||||
char * ptr =
|
||||
#endif
|
||||
this->DeSerialize(buf);
|
||||
size = this->SizeOf();
|
||||
#ifdef _DEBUG
|
||||
RAssert(ptr-buf==size);
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif // NO_BERKELEY
|
||||
|
||||
#endif //_CHAIN_MEM_BERKELEYDB_
|
||||
106
src/meshlabplugins/edit_ocme/src/ocme/berkeleydb/chain_mem_simpledb.h
Executable file
106
src/meshlabplugins/edit_ocme/src/ocme/berkeleydb/chain_mem_simpledb.h
Executable file
@ -0,0 +1,106 @@
|
||||
|
||||
#ifndef _CHAIN_MEM_SIMPLEDB_
|
||||
#define _CHAIN_MEM_SIMPLEDB_
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <cstdlib>
|
||||
|
||||
#include "berkeleyDb.hpp"
|
||||
#include "../chain_mem.h"
|
||||
|
||||
extern SimpleDb * simpledb;
|
||||
|
||||
template < class HandleChunkType>
|
||||
void OOCEnv< HandleChunkType>::
|
||||
Create( const char * name ){
|
||||
simpledb = new SimpleDb(std::string(""), std::string(name),true);
|
||||
}
|
||||
|
||||
template < typename HandleChunkType>
|
||||
void OOCEnv< HandleChunkType>::
|
||||
Open( const char * name ){
|
||||
simpledb = new SimpleDb(std::string(""), std::string(name),false);
|
||||
}
|
||||
|
||||
|
||||
template < typename HandleChunkType>
|
||||
void OOCEnv< HandleChunkType>::
|
||||
Close( bool andsave){
|
||||
if(andsave){
|
||||
SaveAT();
|
||||
SaveData();
|
||||
}
|
||||
delete simpledb;
|
||||
}
|
||||
|
||||
|
||||
template <class TYPE> void Chain<TYPE>::
|
||||
SaveChunk( typename Chain<TYPE>::Chunk & ck ){
|
||||
RAssert(ck.IsLoaded());
|
||||
simpledb->SaveSegment(ck.handle.key,(char*)ck.buffer,sizeof(TYPE)*ck.capacity);
|
||||
}
|
||||
|
||||
template <class TYPE> void Chain<TYPE>::
|
||||
RemoveChunk( typename Chain<TYPE>::Chunk & ck ){
|
||||
RAssert(MemDbg::CheckHeap(0));
|
||||
/* NOT IMPLEMENTED */
|
||||
}
|
||||
|
||||
template <class TYPE> void Chain<TYPE>::
|
||||
FetchChunk( typename Chain<TYPE>::Chunk & ck ){
|
||||
RAssert(MemDbg::CheckHeap(1));
|
||||
ck.buffer = new TYPE[ck.capacity];
|
||||
lgn->chunks_mem+=sizeof(TYPE)*ck.capacity;
|
||||
simpledb->LoadSegment(ck.handle.key.c_str(), (char*)ck.buffer);
|
||||
}
|
||||
|
||||
template < typename HandleChunkType>
|
||||
void OOCEnv< HandleChunkType>::
|
||||
SaveAT( ){
|
||||
|
||||
int siz = this->SizeOf(); // size of the Allocation Table
|
||||
char * buf = new char[siz]; // allocate memory
|
||||
#ifdef _DEBUG
|
||||
char * res =
|
||||
#endif
|
||||
this->Serialize(buf); // serialize
|
||||
#ifdef _DEBUG
|
||||
RAssert(res-buf == siz);
|
||||
#endif
|
||||
|
||||
char title[65];
|
||||
sprintf(&title[0],"%s","CHAINMEM_ALLOCATION_TABLE");
|
||||
|
||||
|
||||
#ifdef _DEBUG
|
||||
int result =
|
||||
#endif
|
||||
simpledb->SaveSegment(std::string(title), buf,siz);
|
||||
delete buf;
|
||||
#ifdef _DEBUG
|
||||
RAssert(result==0);
|
||||
#endif
|
||||
}
|
||||
|
||||
template < typename HandleChunkType>
|
||||
void OOCEnv< HandleChunkType>::
|
||||
LoadAT( ){
|
||||
char title[65];
|
||||
int size;
|
||||
sprintf(&title[0],"%s","CHAINMEM_ALLOCATION_TABLE");
|
||||
char * buf = new char[simpledb->SizeSegment(std::string(title))];
|
||||
|
||||
simpledb->LoadSegment(std::string(title), buf);
|
||||
#ifdef _DEBUG
|
||||
char * ptr =
|
||||
#endif
|
||||
this->DeSerialize(buf);
|
||||
size = this->SizeOf();
|
||||
#ifdef _DEBUG
|
||||
RAssert(ptr-buf==size);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
#endif //_CHAIN_MEM_SIMPLEDB
|
||||
@ -1,111 +1,6 @@
|
||||
#include "../ocme_disk_loader.h"
|
||||
#include "../utils/memory_debug.h"
|
||||
|
||||
#ifndef NO_BERKELEY
|
||||
// File: excxx_example_database_read.cpp
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <cstdlib>
|
||||
|
||||
#include "../ooc_vector/berkeleydb/berkeleydb.hpp"
|
||||
#include "../ocme_definition.h"
|
||||
#include "../impostor_definition.h"
|
||||
#include "../../utils/timing.h"
|
||||
|
||||
|
||||
void
|
||||
OCME::Save( ){
|
||||
TIM::Begin(11);
|
||||
int siz = this->SizeOf(); // size of the Multigrid Table
|
||||
char * buf = new char[siz]; // allocate memory
|
||||
|
||||
char * res = this->Serialize(buf); // serialize
|
||||
RAssert(res-buf == siz);
|
||||
char title[65];
|
||||
sprintf(&title[0],"%s","MULTIGRID_TABLE");
|
||||
Dbt key(&title[0], (u_int32_t)strlen("MULTIGRID_TABLE") + 1);
|
||||
Dbt data(buf, siz);
|
||||
|
||||
int result = ((BerkeleyDb*)extMemHnd)->getDb().put(NULL, &key, &data, 0) ;
|
||||
RAssert(result==0);
|
||||
|
||||
delete [] buf;
|
||||
sprintf(lgn->Buf(),"ocme table:%d",siz);
|
||||
lgn->Push();
|
||||
|
||||
stat.size_ocme_table = siz;
|
||||
|
||||
sprintf(lgn->Buf(),"saving the impostors data..");
|
||||
lgn->Push();
|
||||
unsigned int start =clock();
|
||||
CellsIterator ci;
|
||||
for(ci = cells.begin(); ci != cells.end();++ci)
|
||||
{
|
||||
(*ci).second->impostor->SetCentroids();
|
||||
SaveImpostor((*ci).second);
|
||||
}
|
||||
sprintf(lgn->Buf(),"..done in %f",(clock()-start)/float(CLOCKS_PER_SEC));
|
||||
lgn->Push();
|
||||
|
||||
TIM::End(11);
|
||||
|
||||
}
|
||||
|
||||
|
||||
void OCME::LoadImpostor(Cell * c){
|
||||
|
||||
}
|
||||
|
||||
void OCME::SaveImpostor(Cell * c){
|
||||
static int n=0;
|
||||
char title[255];
|
||||
RAssert(MemDbg::CheckHeap(0));
|
||||
int siz =c->impostor->SizeOf();
|
||||
if(siz == 32 ) return; // it means that only vn and fn have been written->no impostor
|
||||
char * buf = new char[siz];
|
||||
c->impostor->Serialize(buf);
|
||||
|
||||
sprintf(&title[0],"%s_impostor",ToString(c->key).c_str());
|
||||
Dbt keyimp(&title[0], (u_int32_t)strlen(&title[0]) + 1);
|
||||
Dbt dataimp(buf, siz);
|
||||
|
||||
int result = ((BerkeleyDb*)extMemHnd)->getDb().put(NULL, &keyimp, &dataimp, 0) ;
|
||||
RAssert(result==0);
|
||||
delete [] buf;
|
||||
stat.size_impostors+=siz;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void OCME::Load( ){
|
||||
Dbt data;
|
||||
char title[65];
|
||||
sprintf(&title[0],"%s","MULTIGRID_TABLE");
|
||||
Dbt key(&title[0], (u_int32_t)strlen("MULTIGRID_TABLE") + 1);
|
||||
data.set_flags(DB_DBT_MALLOC);
|
||||
int res = ((BerkeleyDb*)extMemHnd)->getDb().get(NULL, &key, &data, 0);
|
||||
if(res == DB_NOTFOUND)
|
||||
printf("MULTIGRID_TABLE not found");
|
||||
|
||||
TIM::Begin(10);
|
||||
this->DeSerialize((char*)data.get_data());
|
||||
|
||||
// load the impostors
|
||||
for(CellsIterator ci = this->cells.begin(); ci != this->cells.end(); ++ci){
|
||||
sprintf(&title[0],"%s_impostor",ToString((*ci).second->key).c_str());
|
||||
Dbt keyimp(&title[0], (u_int32_t)strlen(&title[0]) + 1);
|
||||
res = ((BerkeleyDb*)extMemHnd)->getDb().get(NULL, &keyimp, &data, 0);
|
||||
if(res != DB_NOTFOUND)
|
||||
{
|
||||
(*ci).second->impostor = new Impostor();
|
||||
(*ci).second->impostor->DeSerialize((char*)data.get_data());
|
||||
}
|
||||
}
|
||||
TIM::End(10);
|
||||
|
||||
}
|
||||
#else
|
||||
// File: excxx_example_database_read.cpp
|
||||
|
||||
#include <iostream>
|
||||
@ -219,5 +114,5 @@ void OCME::RemoveImpostor(const CellKey & key){
|
||||
sprintf(&title[0],"%s_impostor",ToString(key).c_str());
|
||||
((SimpleDb*)extMemHnd)->Del(title);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user