How to Store Dynamic Data in App

Started by
4 comments, last by gretty 14 years, 2 months ago
Hello I am new to programming applications(win32) & I am trying to learn the best & conventional ways to structure an application. I have a question about where I should store my "dynamic data" in my application. When I talk about dynamic data I dont mean like "int a = new int;". I will give an example of what I am talking about... I have an application that reads/searches a folder(dir) of music files & creates a random playlist, the apllication stores the most recently searched directory(folder) path in a string, eg 'string lastPath= "C:/users/Jake/Desktop/Music" ', so that this string will be loaded into an editbox the next time the application is loaded. And when a different directory is searched, that directory now becomes the contents of the string lastPath. So that variable is constantly being updated everytime the application is used. - What would I call this kind of data? Dynamic data, isn't right is it? - What is the best &/or conventional way to store & update this data(string lastPath)? Would it be: (& which would be best for win32 apps or for other apps) - SQL file - Text File - In binary in a text file - In the actual cpp file & then each time I run the app I update my own source code (is this possible?)
Advertisement
I think "persistent" data is a better name. It's data that "persists" between runs of your program.

You've got a lot of options:
  1. Store it in a file under CSIDL_APPDATA
  2. In the registry
  3. In an SQL database (though this definitely sounds like overkill for what you want here)
There's probably more, but I think the simplest solution is just to store it in a text file under CSIDL_APPDATA (that is, "C:\Users\<username>\AppData\Roaming\*").
Thanks for your reply.

How would I do option 2: Store it in the registry?
You'd use the registry functions.
If you need to store lots of data and do quick look ups (like for example if you store a complete playlist with thousands of songs) then you can combine Codeka's suggestion 1 and 3 by using SQLite. It gives you a fairly complete SQL database in a single file.

As an user I much prefer apps that writes a config file to APPDATA over using the registry. The registry quickly becomes cluttered and makes Windows dog slow since it's almost impossible to clean up probably. With APPDATA I can always just delete the files.

Btw. I just learned today that from Vista forwards it's not CSIDL_* anymore, but FOLDERID through the Known Folders API.

Quote:Original post by Promethium
If you need to store lots of data and do quick look ups (like for example if you store a complete playlist with thousands of songs) then you can combine Codeka's suggestion 1 and 3 by using SQLite. It gives you a fairly complete SQL database in a single file.

As an user I much prefer apps that writes a config file to APPDATA over using the registry. The registry quickly becomes cluttered and makes Windows dog slow since it's almost impossible to clean up probably. With APPDATA I can always just delete the files.

Btw. I just learned today that from Vista forwards it's not CSIDL_* anymore, but FOLDERID through the Known Folders API.


Thanks guys :D

I think I'll take your advice & try APPDATA. Good advice on registry vs. APPDATA, its nice to learn these things :)

This topic is closed to new replies.

Advertisement