Dumping memory to file

前端 未结 5 600
囚心锁ツ
囚心锁ツ 2021-01-05 11:57

I\'ve got a part of my memory that I want to dump to a file. One reason is to save the information somewhere, and another is to read it again when my program restarts.

5条回答
  •  我在风中等你
    2021-01-05 12:12

    The proper way of doing that is to use a serialisation library.

    Whether you really need that depends on the complexity of your data. If the data you need to write out does not contain any pointers of any kind, then you could just use fwrite to write the data out and fread to read it back in. Just make sure that you have opened the file with the data in binary mode.

    If the data to serialise contains pointers, you are way better of using an external library written for this purpose, as the library will ensure that the pointers get written in such a way that they can be properly reconstructed later.

提交回复
热议问题