c++data-serialization

What is the best way to binarize data


I have some data files that are written as tag = value, where tag is string and value may be numeric, string, array, etc. I use this format because is readable and can be edited easy. Now every class that is instantiated using this format has a load method and it reads the tags that it needs and use the values found within these tags. I want to make data binary to increase loading speed. One way would be to have a ToBinary(the name does not matter) method in every class that reads the old data and write it in a file and the new file is used to instantiate the object. This can be done offline, only once/application. Do you have other suggestions for this? I use C++ for this.

Edit: I think the most expensive part now is to parse the file when I first read it and after that to search the tag that I need, not to read the file from disk. I can use custom file system to have multiple small files in one big file.


Solution

  • I have a serialization base class for this, with To/From functions with a small header where version handling can be embedded. I think its a good system for simpler data that needs to be stored locally and in most cases is "read only".

    Something like this:

    class SeralizeMe
    {
    public:
    
     virtual bool To(Archive &file)=0;
     virtual bool From(Archive &file)=0;
    
     virtual bool NeedsSave(void)=0;
    
    };
    

    However, do not use this system if you:

    If any of above apply , use a database , FirebirdSQL embedded is a suitable contender.