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();
|
||||
size = 0;
|
||||
readonly = false;
|
||||
assert(mxs <= (1<<30));
|
||||
assert(mxs <= MFILE_MAX_SIZE);
|
||||
max_size = mxs;
|
||||
return AddFile();
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ bool MFile::Load(const string &fname, bool ronly) {
|
|||
filename = fname;
|
||||
files.clear();
|
||||
readonly = ronly;
|
||||
max_size = (1<<30);
|
||||
max_size = MFILE_MAX_SIZE;
|
||||
size = 0;
|
||||
|
||||
while(1) {
|
||||
|
@ -57,12 +57,14 @@ void MFile::Redim(int64 sz) {
|
|||
if(sz > size) {
|
||||
unsigned int totfile = (unsigned int)(sz/max_size);
|
||||
//TODO test rhis!!!!
|
||||
while(files.size() < totfile) {
|
||||
while(files.size() <= totfile) {
|
||||
RedimLast(max_size);
|
||||
assert(size == max_size * (files.size()));
|
||||
AddFile();
|
||||
}
|
||||
assert(size < sz);
|
||||
assert(size <= sz);
|
||||
assert(sz - size < max_size);
|
||||
assert(files.back().Length() + (unsigned int)(sz - size) < max_size);
|
||||
RedimLast(files.back().Length() + (unsigned int)(sz - size));
|
||||
} else {
|
||||
while(size - files.back().Length() > sz)
|
||||
|
@ -75,7 +77,8 @@ void MFile::Redim(int64 sz) {
|
|||
void MFile::SetPosition(int64 pos) {
|
||||
assert(pos < 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());
|
||||
files[curr_fp].SetPosition(curr_pos);
|
||||
}
|
||||
|
@ -129,7 +132,8 @@ void MFile::WriteBuffer(void *data, unsigned int sz) {
|
|||
#endif
|
||||
}
|
||||
|
||||
void MFile::RedimLast(unsigned int sz) {
|
||||
void MFile::RedimLast(unsigned int sz) {
|
||||
assert(sz <= max_size);
|
||||
File &file = files.back();
|
||||
unsigned int last_size = file.Length();
|
||||
file.Redim(sz);
|
||||
|
|
|
@ -14,6 +14,8 @@ typedef __int64 int64;
|
|||
typedef unsigned long long int64;
|
||||
#endif
|
||||
|
||||
#define MFILE_MAX_SIZE (1<<30)
|
||||
|
||||
class MFile {
|
||||
public:
|
||||
|
||||
|
@ -22,7 +24,7 @@ class MFile {
|
|||
|
||||
//max is so default is 1 G
|
||||
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);
|
||||
void Close();
|
||||
|
||||
|
|
|
@ -219,22 +219,22 @@ void PatchServer::Flush(PTime &ptime) {
|
|||
char *compressed = ptime.patch->Compress(entry.ram_size * chunk_size,
|
||||
compressed_size);
|
||||
if(entry.disk_size == 0xffff) {//allocate space
|
||||
assert(entry.patch_start == 0xffffffff);
|
||||
entry.disk_size = (unsigned int)((compressed_size-1)/chunk_size) + 1;
|
||||
entry.patch_start = (unsigned int)(Length()/chunk_size);
|
||||
Redim(Length() + entry.disk_size * chunk_size);
|
||||
assert(entry.patch_start == 0xffffffff);
|
||||
entry.disk_size = (unsigned int)((compressed_size-1)/chunk_size) + 1;
|
||||
entry.patch_start = (unsigned int)(Length()/chunk_size);
|
||||
Redim(Length() + entry.disk_size * chunk_size);
|
||||
} else {
|
||||
cerr << "OOOOPSPPPS not supported!" << endl;
|
||||
exit(-1);
|
||||
cerr << "OOOOPSPPPS not supported!" << endl;
|
||||
exit(-1);
|
||||
}
|
||||
SetPosition(entry.patch_start * chunk_size);
|
||||
WriteBuffer(compressed, entry.disk_size * chunk_size);
|
||||
delete []compressed;
|
||||
} else {
|
||||
if(entry.disk_size == 0xffff) {
|
||||
entry.disk_size = entry.ram_size;
|
||||
entry.patch_start = (unsigned int)(Length()/chunk_size);
|
||||
Redim(Length() + entry.disk_size * chunk_size);
|
||||
entry.disk_size = entry.ram_size;
|
||||
entry.patch_start = (unsigned int)(Length()/chunk_size);
|
||||
Redim(Length() + entry.disk_size * chunk_size);
|
||||
}
|
||||
SetPosition(entry.patch_start * chunk_size);
|
||||
WriteBuffer(ptime.patch->start, entry.disk_size * chunk_size);
|
||||
|
|
Loading…
Reference in New Issue