Debugging, debugging, debugging.

This commit is contained in:
Federico Ponchio 2004-10-21 15:05:39 +00:00
parent 625216a999
commit 7745578c97
3 changed files with 22 additions and 16 deletions

View File

@ -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)
@ -75,7 +77,8 @@ void MFile::Redim(int64 sz) {
void MFile::SetPosition(int64 pos) { 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);
} }
@ -129,7 +132,8 @@ void MFile::WriteBuffer(void *data, unsigned int sz) {
#endif #endif
} }
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);

View File

@ -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();

View File

@ -219,22 +219,22 @@ void PatchServer::Flush(PTime &ptime) {
char *compressed = ptime.patch->Compress(entry.ram_size * chunk_size, char *compressed = ptime.patch->Compress(entry.ram_size * chunk_size,
compressed_size); compressed_size);
if(entry.disk_size == 0xffff) {//allocate space if(entry.disk_size == 0xffff) {//allocate space
assert(entry.patch_start == 0xffffffff); assert(entry.patch_start == 0xffffffff);
entry.disk_size = (unsigned int)((compressed_size-1)/chunk_size) + 1; entry.disk_size = (unsigned int)((compressed_size-1)/chunk_size) + 1;
entry.patch_start = (unsigned int)(Length()/chunk_size); entry.patch_start = (unsigned int)(Length()/chunk_size);
Redim(Length() + entry.disk_size * chunk_size); Redim(Length() + entry.disk_size * chunk_size);
} else { } else {
cerr << "OOOOPSPPPS not supported!" << endl; cerr << "OOOOPSPPPS not supported!" << endl;
exit(-1); exit(-1);
} }
SetPosition(entry.patch_start * chunk_size); SetPosition(entry.patch_start * chunk_size);
WriteBuffer(compressed, entry.disk_size * chunk_size); WriteBuffer(compressed, entry.disk_size * chunk_size);
delete []compressed; delete []compressed;
} else { } else {
if(entry.disk_size == 0xffff) { if(entry.disk_size == 0xffff) {
entry.disk_size = entry.ram_size; entry.disk_size = entry.ram_size;
entry.patch_start = (unsigned int)(Length()/chunk_size); entry.patch_start = (unsigned int)(Length()/chunk_size);
Redim(Length() + entry.disk_size * chunk_size); Redim(Length() + entry.disk_size * chunk_size);
} }
SetPosition(entry.patch_start * chunk_size); SetPosition(entry.patch_start * chunk_size);
WriteBuffer(ptime.patch->start, entry.disk_size * chunk_size); WriteBuffer(ptime.patch->start, entry.disk_size * chunk_size);