Debugging, debugging, debugging.
This commit is contained in:
parent
625216a999
commit
7745578c97
|
@ -10,7 +10,7 @@ bool MFile::Create(const string &fname, unsigned int mxs) {
|
||||||
files.clear();
|
files.clear();
|
||||||
size = 0;
|
size = 0;
|
||||||
readonly = false;
|
readonly = false;
|
||||||
assert(mxs <= (1<<30));
|
assert(mxs <= MFILE_MAX_SIZE);
|
||||||
max_size = mxs;
|
max_size = mxs;
|
||||||
return AddFile();
|
return AddFile();
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,7 @@ bool MFile::Load(const string &fname, bool ronly) {
|
||||||
filename = fname;
|
filename = fname;
|
||||||
files.clear();
|
files.clear();
|
||||||
readonly = ronly;
|
readonly = ronly;
|
||||||
max_size = (1<<30);
|
max_size = MFILE_MAX_SIZE;
|
||||||
size = 0;
|
size = 0;
|
||||||
|
|
||||||
while(1) {
|
while(1) {
|
||||||
|
@ -57,12 +57,14 @@ void MFile::Redim(int64 sz) {
|
||||||
if(sz > size) {
|
if(sz > size) {
|
||||||
unsigned int totfile = (unsigned int)(sz/max_size);
|
unsigned int totfile = (unsigned int)(sz/max_size);
|
||||||
//TODO test rhis!!!!
|
//TODO test rhis!!!!
|
||||||
while(files.size() < totfile) {
|
while(files.size() <= totfile) {
|
||||||
RedimLast(max_size);
|
RedimLast(max_size);
|
||||||
|
assert(size == max_size * (files.size()));
|
||||||
AddFile();
|
AddFile();
|
||||||
}
|
}
|
||||||
assert(size < sz);
|
assert(size <= sz);
|
||||||
assert(sz - size < max_size);
|
assert(sz - size < max_size);
|
||||||
|
assert(files.back().Length() + (unsigned int)(sz - size) < max_size);
|
||||||
RedimLast(files.back().Length() + (unsigned int)(sz - size));
|
RedimLast(files.back().Length() + (unsigned int)(sz - size));
|
||||||
} else {
|
} else {
|
||||||
while(size - files.back().Length() > sz)
|
while(size - files.back().Length() > sz)
|
||||||
|
@ -76,6 +78,7 @@ void MFile::SetPosition(int64 pos) {
|
||||||
assert(pos < size);
|
assert(pos < size);
|
||||||
curr_fp = (unsigned int)(pos/(int64)max_size);
|
curr_fp = (unsigned int)(pos/(int64)max_size);
|
||||||
curr_pos = (unsigned int)(pos - (int64)max_size * (int64)curr_fp);
|
curr_pos = (unsigned int)(pos - (int64)max_size * (int64)curr_fp);
|
||||||
|
assert(curr_pos < max_size);
|
||||||
assert(curr_fp < files.size());
|
assert(curr_fp < files.size());
|
||||||
files[curr_fp].SetPosition(curr_pos);
|
files[curr_fp].SetPosition(curr_pos);
|
||||||
}
|
}
|
||||||
|
@ -130,6 +133,7 @@ void MFile::WriteBuffer(void *data, unsigned int sz) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void MFile::RedimLast(unsigned int sz) {
|
void MFile::RedimLast(unsigned int sz) {
|
||||||
|
assert(sz <= max_size);
|
||||||
File &file = files.back();
|
File &file = files.back();
|
||||||
unsigned int last_size = file.Length();
|
unsigned int last_size = file.Length();
|
||||||
file.Redim(sz);
|
file.Redim(sz);
|
||||||
|
|
|
@ -14,6 +14,8 @@ typedef __int64 int64;
|
||||||
typedef unsigned long long int64;
|
typedef unsigned long long int64;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define MFILE_MAX_SIZE (1<<30)
|
||||||
|
|
||||||
class MFile {
|
class MFile {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
@ -22,7 +24,7 @@ class MFile {
|
||||||
|
|
||||||
//max is so default is 1 G
|
//max is so default is 1 G
|
||||||
bool Create(const std::string &filename,
|
bool Create(const std::string &filename,
|
||||||
unsigned int max_file_size = (1<<30));
|
unsigned int max_file_size = MFILE_MAX_SIZE);
|
||||||
bool Load(const std::string &filename, bool readonly = false);
|
bool Load(const std::string &filename, bool readonly = false);
|
||||||
void Close();
|
void Close();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue