Did a forum search on "Write structure" and also "Save structure" to disk, came up with 30 possible pages and I know I saw it somewhere before...
Given a structure as below and a linked list based on it, is there a way to easily save the elements of each line in the list without having to individually specify them?
hiya Fangbeast please forigve me if im misunderstanding your question!
but i dont think there is a much easier way than iterating each item. If it was a single solid structure you could just use @ to get address, SizeOf to get size, and WriteData to file, but because strings in a structure are just pointers it's not a single solid structure as you probably know! Perhaps you could test to see if the locations of all the pointed strings are in a contiguous memory so that the first and last items are also first and last in memory, and with all other items inbetween... then you could just call WriteData twice, but i dont think it would be contiguous because it needs to allow for dynamic resizing of strings so they could get relocated? i stop thinking now
Keya wrote:hiya Fangbeast please forigve me if im misunderstanding your question!
but i dont think there is a much easier way than iterating each item. If it was a single solid structure you could just use @ to get address, SizeOf to get size, and WriteData to file, but because strings in a structure are just pointers it's not a single solid structure as you probably know! Perhaps you could test to see if the locations of all the pointed strings are in a contiguous memory so that the first and last items are also first and last in memory, and with all other items inbetween... then you could just call WriteData twice, but i dont think it would be contiguous because it needs to allow for dynamic resizing of strings so they could get relocated? i stop thinking now
That's pretty impresive ostapas. No way my tiny brain would have ever thought of that.
When I do a raw log dump, the file is 375K. When I do an xml or json dump as shown, the log is just shy of 3 meg so your compression idea is great. Thank you.
Are there alternatives to save/load a complex structure (in a binary way for example)? JSON text parsing and writing is extremely slow....
Would be nice to have such functions like StructureToMemory() or StructureFromMemory() to transfer a structure to a single memory block (and vice versa) which you can compress, encrypt and/or write to disc...
There are fundamental differences between the pickle protocols and JSON (JavaScript Object Notation):
JSON is a text serialization format (it outputs unicode text, although most of the time it is then encoded to utf-8), while pickle is a binary serialization format;
JSON is human-readable, while pickle is not;
JSON is interoperable and widely used outside of the Python ecosystem, while pickle is Python-specific;
JSON, by default, can only represent a subset of the Python built-in types, and no custom classes; pickle can represent an extremely large number of Python types (many of them automatically, by clever usage of Python’s introspection facilities; complex cases can be tackled by implementing specific object APIs).
All the elements in the structure could be expressed as doubles and integers. Only commit to string when displaying the data in tabular format. Much faster and smaller log.
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
Lebostein wrote:Are there alternatives to save/load a complex structure (in a binary way for example)? JSON text parsing and writing is extremely slow....
I just hate JSON (even for its name itself ^_^), so typically using XML for that which is 1000 times better as for me.
Here is some ready-to-use code, however not sure will it be fast enough for your case http://www.purebasic.fr/english/viewtop ... 12&t=67110
Previously I was using plain binary to store all the stuff, that's better for performance and memory consumption, but really becomes painful if you writing that import/export for everything manually and having large nested structure with strings and so on. Have no any idea how it is possible to automate that "forgotten art of structure packing" nicely.