Reputation: 345
There's a simple C application made using GTK+2. It also has simple data on the interface, and the application needs to save the last used values before closing so that they can be loaded when the application starts again.
I found a few methods to save load data.
Since I'm a beginner with C, either way I need to do a RnD and start implementing. I need to know the best/standard/effective method which is used by C programming professionals for this kind of scenario.
Edit: Nature of data
Data which need to be saved and retrieved are as follows.
Above data is used by the application to draw a diagram on the interface. When the application starts, it should draw the diagram using the old values.
Upvotes: 0
Views: 1031
Reputation: 2201
The straightforward way
The easiest way would be to put the variables you want to store in a struct
. Then you can output/load the content of the struct in/from a file (in binary mode). The pro of this technique is that you do not have to go through all your variables. I would definitely go for this solution if you can close your program properly.
Checkpoint/Restart libraries
In High Performance Computing, when launching a simulation code which takes a long time to execute (or/and using a large amount of compute nodes), it is quite common to use checkpoint/restart libraries. If there is a failure, the program may be restarted from the previous valid checkpoint. It is used more often when something may go wrong during the execution.
Upvotes: 1