In MFC there is such a concept of "Serialization".
You can do this in any language. Basically, you just write procedures to go around your data structure, and as they go, they write the main data in binary form to your file.
When writing an array, make sure that you write the size of the array before its elements.
When writing a pointer-based structure, first write a logical message if the pointer is not null.
Then you write to the reader who does the same, except that he reads the array, first reads the size, selects the array, and reads the elements. At the point where you are reading the pointer, first read the boolean value. If it is 0, just make the pointer null and skip it. If not, highlight the pointer and continue reading its contents.
In MFC, these two functions are actually encoded into common routines called "Serialization". When you write, you basically do depth when you write, and the same when you read.
Since all I / O are binary, it is about as fast as possible.
source share