Safest Binary Store/Get Format?

SephirothSephiroth Fayetteville, NC, USA
OK, now that I can dynamically allocate storage space for my world texture list in memory, I am trying to figure out the best way to store the strings of texture names in my files. Here's an example.
[code]
short int numTex;
char **TexList;
...
numTex = 36;
...
TexList = new char*[numTex];
for(short int Loop = 0; Loop < numTex; Loop++)
TexList[Loop] = new char[32];
[/code]
OK, now "TexList" contains 36 texture filenames. Would it be safer to write the whole TexList as one fread or go in and write it string by string? Here's how it would work.
[code]
...
fwrite(&numTex, sizeof(short int), 1, outputfile);
fwrite(&TexList, sizeof(TexList), 1, outputfile);
...
//Now how it loads...
...
fread(&numTex, sizeof(short int), 1, inputfile);
TexList = new char*[numTex];
for(short int Loop = 0; Loop < numTex; Loop++)
TexList[Loop] = new char[32];

fread(&TexList, sizeof(TexList), 1, inputfile);
...
[/code]
I feel that this method would work, since the world editor would write the number if textures, then slam the whole list into a file, and then the game comes along, sees how many texture strings are needed, allocate that much ram (which would be the SAME as in the editor, correct?) and then load the strings into the array at once. Am I assuming the correct thing here? I am only asking because I think I've permanently damaged my Windoze install while playing around too much and over-writing the kernel, rebooting, and causing the BSOD! I've never had 98SE so much as burp at me, yet since I caused a few GPFs and BSODs, I had "Explorer" stop responding twice. Yech, time to re-install!

-[italic][b][red]S[/red][purple]e[/purple][blue]p[/blue][green]h[/green][red]i[/red][purple]r[/purple][blue]o[/blue][green]t[/green][red]h[/red][/b][/italic]

Comments

  • Hi!

    I'm not into C programming, but if you allocate memory, fill it up, than save the size, and save the memory contents, you should be able to load it back the described way. I'm not realy familiar with C, but ishould work just fine. /Just don't forget to release that memory later on/

    Edocecrous

    : OK, now that I can dynamically allocate storage space for my world texture list in memory, I am trying to figure out the best way to store the strings of texture names in my files. Here's an example.
    : [code]
    : short int numTex;
    : char **TexList;
    : ...
    : numTex = 36;
    : ...
    : TexList = new char*[numTex];
    : for(short int Loop = 0; Loop < numTex; Loop++)
    : TexList[Loop] = new char[32];
    : [/code]
    : OK, now "TexList" contains 36 texture filenames. Would it be safer to write the whole TexList as one fread or go in and write it string by string? Here's how it would work.
    : [code]
    : ...
    : fwrite(&numTex, sizeof(short int), 1, outputfile);
    : fwrite(&TexList, sizeof(TexList), 1, outputfile);
    : ...
    : //Now how it loads...
    : ...
    : fread(&numTex, sizeof(short int), 1, inputfile);
    : TexList = new char*[numTex];
    : for(short int Loop = 0; Loop < numTex; Loop++)
    : TexList[Loop] = new char[32];
    :
    : fread(&TexList, sizeof(TexList), 1, inputfile);
    : ...
    : [/code]
    : I feel that this method would work, since the world editor would write the number if textures, then slam the whole list into a file, and then the game comes along, sees how many texture strings are needed, allocate that much ram (which would be the SAME as in the editor, correct?) and then load the strings into the array at once. Am I assuming the correct thing here? I am only asking because I think I've permanently damaged my Windoze install while playing around too much and over-writing the kernel, rebooting, and causing the BSOD! I've never had 98SE so much as burp at me, yet since I caused a few GPFs and BSODs, I had "Explorer" stop responding twice. Yech, time to re-install!
    :
    : -[italic][b][red]S[/red][purple]e[/purple][blue]p[/blue][green]h[/green][red]i[/red][purple]r[/purple][blue]o[/blue][green]t[/green][red]h[/red][/b][/italic]
    :

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion