Use variable-length structures and binary IO. That will simplify things and also give you the option to use either the "in-memory" or "from file" lookup aproach:
something like:
Code:
class Data {
public:
int size;
int data_length;
char * data;
int extra_length;
char * extra;
};
int index, size, total;
int sin = sizeof(int);
index = size = total = 0;
while(fread(&size, sin, 1, fp)){
++total;
fseek(fp, size-sin, SEEK_CUR);
}
rewind(fp);
Data data[total];
while(fseek(fp, sin, SEEK_CURR)==0){
fread(&size, sin, 1, fp);
data[index].data = new char[size];
fread(data[index].data, 1, size, fp);
fread(&size, sin, 1, fp);
data[index].extra = new char[size];
fread(data[index].extra, 1, size, fp);
++index;
}