Storing Strings - A lot of them.

I'm developing a simple random background switching program--which you might have heard about a while ago. I currently have the program setup to read jpg's that are numbered, as in 1.jpg,2.jpg... which is a tedious for the user. I'm expanding this to include other formats and any filename the user decides to use.

I'm in need of a method of storing filenames which can be dynamically updated at runtime. The issue here is the number of filenames, which is anywhere between 20-2000. So naturally, I don't want my program sitting there trying to read through 2000 files and storing the names in memory. Any thoughts?
I don't want my program [...] storing the names in memory


Why not? The memory is exactly for such thing. Use vector or list to hold data in structures or classes, like:
1
2
3
4
5
6
7
struct file_t
{
string filename; //user defined filename
string file; //file name or FILE pointer/stream on hdd
type_t type;
... // etc
};

and load data when program start.
2000 of such structures will take maybe 60-70 bytes per file (with 50 characters for filename, file) so that would result in ~117 - 136kB of memory used. Not much, since modern PC has like 1GB +.
Last edited on
Topic archived. No new replies allowed.