Howdy, Stranger!

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

Categories

Safest Binary Store/Get Format?

SephirothSephiroth Fayetteville, NC, USAMember Posts: 1,035
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

  • edocecrousedocecrous Member Posts: 49
    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]
    :

  • Chris BrownChris Brown USAMember Posts: 4,496 ✭✭

    ___ [ http://forcoder.org ] free ebooks and video tutorials about < Objective-C, MATLAB, Visual Basic .NET, PL/SQL, Java, Swift, Scratch, Ruby, C#, Perl, JavaScript, Delphi, Python, Go, PHP, C++, C, R, Assembly, Visual Basic Lisp, F#, Clojure, VBScript, Erlang, Apex, COBOL, SAS, Awk, Dart, Lua, Julia, Scala, Alice, Ada, Transact-SQL, FoxPro, Rust, LabVIEW, Fortran, Bash, ABAP, D, Prolog, Hack, Logo, Crystal, Scheme, Kotlin, ML /> ___

Sign In or Register to comment.