Commit b53f05b2 authored by Ivan Donchevskiy's avatar Ivan Donchevskiy

set correct size of journal in CycleStorage

parent 231f2434
......@@ -178,7 +178,7 @@ class CycleStorage
int full_size;
void filewrite(CycleStorageElem* jrn,int seek, bool needflush=true);
void* valPointer(void* pnt);
void findHead();
bool findHead();
};
#endif
......@@ -66,7 +66,7 @@ void CycleStorage::filewrite(CycleStorageElem* jrn,int seek,bool needflush)
( 2 - 4 , ), 3 - 2, 5 - 4, 6 - 1.
|
*/
void CycleStorage::findHead()
bool CycleStorage::findHead()
{
CycleStorageElem *jrn = (CycleStorageElem*)new char[full_size];
int l=-1,r=size,mid;
......@@ -116,11 +116,13 @@ void CycleStorage::findHead()
l = mid;
else if((jrn->status==j)||(jrn->status==j+1))
r = mid;
else
else if((jrn->status==1)||(jrn->status==6))
{
r=mid;
break;
}
else
return false;
}
if(r<size)
head=r;
......@@ -130,6 +132,7 @@ void CycleStorage::findHead()
if(tail<0) tail=size-1;
}
delete jrn;
return true;
}
bool CycleStorage::open(const char* name, int inf_sz, int inf_count, int seek)
......@@ -148,19 +151,17 @@ bool CycleStorage::open(const char* name, int inf_sz, int inf_count, int seek)
CycleStorageAttr csa;
fread(&csa,sizeof(csa),1,file);
int sz = inf_sz * inf_count;
/*! */
if((csa.size!=(int)((sz-sizeof(csa))/(sizeof(CycleStorageElem)+inf_sz)))||(csa.inf_size!=inf_sz)||(csa.seekpos!=seek))
if((csa.size!=inf_count)||(csa.inf_size!=inf_sz)||(csa.seekpos!=seek))
return false;
inf_size=inf_sz;
full_size=sizeof(CycleStorageElem)+inf_size;
size=(sz-sizeof(csa))/full_size;
size=inf_count;
seekpos=seek;
seekpos+=sizeof(CycleStorageAttr);
findHead();
if(!findHead())
return false;
return true;
}
......@@ -176,12 +177,11 @@ bool CycleStorage::create(const char* name, int inf_sz, int inf_count, int seek)
file = fopen(name, "r+");
}
int sz = inf_sz * inf_count;
inf_size=inf_sz;
full_size=sizeof(CycleStorageElem)+inf_size;
size=(sz-sizeof(CycleStorageAttr))/full_size;
size=inf_count;
iter=0;
seekpos=seek;
......@@ -207,16 +207,6 @@ bool CycleStorage::create(const char* name, int inf_sz, int inf_count, int seek)
filewrite(jrn,i,false);
}
fflush(file);
/*! , , */
int emp = sz-size*full_size-sizeof(CycleStorageAttr);
if(emp>0)
{
char* empty= new char[emp];
fwrite(empty,emp,1,file);
fflush(file);
delete empty;
}
head=tail=-1;
delete jrn;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment