Simply writing binary images to memory is a form of serialization, and for trivial cases, it works. However, in general, you need to solve a few more problems that do not flush memory:
1. Pointers
If the data contains any pointer, you certainly cannot simply unload the load later, because the memory address pointed to by the pointers will not matter as soon as the program terminates and restarts. Many objects have “hidden” pointers ... for example, there is no way to reset std::vector in memory and reload it later correctly ... sizeof on std::vector does not explicitly include the size of the contained elements and therefore any structure containing std::vector , cannot be simply reset and rebooted. The same goes for std::string and all other std containers.
2. Portability
The structure and classes of C and C ++ are not defined in terms of the bytes they occupy in memory, and are not portable. This means that another compiler, another version of the compiler, or even the same version, but with different compilation options, can generate code in which the structure structure in memory is not the same.
If you need serialization to just save and reload data in the same program, and data that it should not live for long, then you can use memory dump. Just think about having millions of documents saved only by dumping structures, and now the new version of the compiler (which you force to use because it is supported only in the new OS version) has a different layout and you cannot load these documents.
In addition to the portability problems of the same system, note also that even a single integer can have a different representation in memory on different systems. It can be more or less; it may have a different byte order. Just using a memory dump means that what is saved cannot be loaded by another system. Even one.
3. Versioning
If the stored data will have a long service life, then it is likely that you will change the structure as the program develops, for example, you will add new fields, you will delete unused fields, you will change the general structure (for example, changing a vector in a linked list).
If your format is just memory images of existing data structures, it will be quite difficult to add, for example, the color field to the polygon object, so that the program can load old documents, assuming that the default value is the color that was used in the previous version.
Even writing a conversion program will be difficult, because you will have old code that can load old documents and new code that can save new documents, but you can’t just “merge” these two and get a program that downloads old ones and saves new ones (t .e., the source code of both programs will have a polygon structure, but with different fields, now what?).