[SOLVED] Size of serialized data.
Now I am writing a code for saving data into the file. Usually data files have header at the beginning where table with offsets is located. For example I want to save 10 objects into my file, each object have quite large size. Size of each objects could be different. So, to read one object I need to know its offset into the file (If I don't want to read every object before). Of course I can do that manually, just by calculating size of each serialized object, but at this point it seems that I will have to do a lot of tedious work with sizeof(), because each object has a lot of related dynamic data. My question is what is the best way to generate this table while writing file, may be there are some sort of patterns which are used in this case, or special classes/functions in Qt?
My question is what is the best way to generate this table while writing file
That really depends on how your data is structured, and how you want to use it.
Could you provide more details?
may be there are some sort of patterns which are used in this case, or special classes/functions in Qt?
There are many ways to save data to disk. Here are 3 options:
- You can use QDataStream to convert Qt objects to/from raw bytes: http://doc.qt.io/qt-5/qdatastream.html
- You can use Qt SQL classes to read/write table data: http://doc.qt.io/qt-5/examples-sql.html
- You can convert your data to/from a JSON document: http://doc.qt.io/qt-5/qtcore-json-savegame-example.html
I think I managed to overcome this problem, so there is no need in further discussion of details : )/
tnx for links!