Okay, I'm completely stuck loading a struct from a binary file, saving looks fine to me but on loading i get a bad_allocation exception, may someone please show me how to load/save a struct like this(yes i searched for too many hours and 0 results)
Code:
typedef struct CColumn
{
int ID;
string UniqueName;
}Column;
typedef struct CVar
{
string ColName;
string Value;
}Variable;
typedef struct CRow
{
int Number;
Variable * Variables;
}Row;
typedef struct CTable
{
int ID;
int RowsCount;
int ColumnsCount;
string Name;
Column * Columns;
Row * Rows;
}Table;
Table struct has to be saved in a file, then loaded from the file; Columns and Rows are dynamic arrays.
If the load/save functions are needed please tell me and I'll post them.
Mfg,
Nullable.
You know your loading function is not working and you need help, but you don't post it? Yea I thought so...
My loading function is full of useless commented out tests, basically i'd say crap, that's why i'd rather have an example than post my crappy method
anyhow:
Problems start when reading the header(supposed to return 92) but it returns a huge -ve integer(-12283453 not exact).
so
Quote:
char * Stream = new char[TableSize];
this part would return a bad_allocation exp(-ve capacity ftw!) hence i can load nothing
I also tried writing the struct itself into the file and load it same way, but it never works(also returns bad_allocation)
BufferBuilder is just a small class to write data to the buffer..
How about using C++-Strings instead of using old C-strings in your C++ Project? By using the std::string class you will not have problems like a buffer overflow or allocating memory errors. Furthermore you should de-allocate the memory you have allocated with "new" otherwise you will get memory leaks especially when you use pointers.
How about using C++-Strings instead of using old C-strings in your C++ Project? By using the std::string class you will not have problems like a buffer overflow or allocating memory errors. Furthermore you should de-allocate the memory you have allocated with "new" otherwise you will get memory leaks especially when you use pointers.
I didn't mention my bufferbuilder class already does the deleting in the destructor, and about purely using the string class.. I don't think that even relates to the problem(but i might actually try doing it, thanks for the idea), because i never get the size header in the file correctly, i did some tests and the buffer written is fine, contains the header, and everything in the table struct, i even loaded it after writing and it looks all fine, but as soon as it is written to the file, somehow i can't seem to load the size header correctly, which then hinders me from completing loading(I can't get any further, don't know the correct size).
How about using C++-Strings instead of using old C-strings in your C++ Project? By using the std::string class you will not have problems like a buffer overflow or allocating memory errors. Furthermore you should de-allocate the memory you have allocated with "new" otherwise you will get memory leaks especially when you use pointers.
Self-explanatory
Stupid
You should of have noticed that the OP is using byte buffers instead of strings.
Mhm. Maybe it would be a good idea if you show us the saving function. But why do you use a binary file? It would be easier if you save it like this:
Ehm, Table contains dynamic arrays of Column, and Row, then Row contains a dynamic array of Variables, my idea is to dump them all into a file from the table struct, and then be able to read them all dynamically in the table struct with their dynamic arrays initialized and filled up, without even specifying the number of variables that exist in the table(supposed that i don't know how many, but i would know when loading from the file) but i might tweak your method a bit to satisfy the needs, thanks.
I know that getline() is completely wrong when working with binary files. That's why I suggested to save the structure like a ".ini" file. You should read my posts better
I know that getline() is completely wrong when working with binary files. That's why I suggested to save the structure like a ".ini" file. You should read my posts better
Yeah, ands thats a waste of space and much less efficient.
Oh come on. Any time I try to help, you criticise my suggestions. First ImmuneOne complained about my "stupid" idea but he did not have a better suggestion instead. Then you moan about my idea to use a filesystem like an ini-file. Of course he can only save the needen information:
Code:
12345|12|24|Test|11|Bla|1|Blub|val
Furthermore he can create a database system to handle the dynamic arrays of the structures.
I didn't really mention how was my problem solved, but anyway it was a reason different from anything posted all over the latter posts *cough* wrong path *cough*
TQ New Binary Files 09/26/2009 - EO PServer Hosting - 0 Replies well i put it in the reply on the one tread but after all the bad comments i figured no one would see it so i am making a new post for it. Well i found the download of the files and i upladed them on 4shared. Here is the link for the downlad
4shared.com - online file sharing and storage - download TQ New Binary Files
This was the image everyone was talking about. I am not taking credit for someone work just figured i see if u guys could use the files.
Well i will let u all figure out the...
[Guide] How To Translate A NPC In Binary Files 06/15/2009 - CO2 PServer Guides & Releases - 12 Replies I am proud to release my guide how to translate a NPC in the binarys enjoy.
1 :- Download The Easy NPC Translator from the attchment
2 :- Extracted the Easy Npc Translator and run it.
[HELP] TQ BINARY files 01/17/2009 - CO2 Private Server - 0 Replies Hey guys, i currently got TQ binary files working, just when i open client and login it allows me to login it just closes client, anyone know a solution to stop this? ;s