When to Choose Memory over Disk Access and Vise Versa

A user could potentially have selected many items in a listbox. A listbox line represents a record in a database. There may or may not be a time when a long text string needs to be generated for each item in the selection. The text string will contain all record data and related data of the selected item.

Is it safe to hold the record data and related data in each rowtag if many rows could possibly be selected? Or is it safer to loop through the selected lines, accessing the disk each time, only when it is definitely known that the text file needs to be created? I believe this will reduce memory consumption, but will this be a significant slow down?

Thank you

If you are compiling a 32 bit app, a rough rule of thumb is that you can safely store about 1GB of data in RAM (yes, technically you should be able to store up to 4GB but with overhead, caching, etc. I like to play it safe).

You can then calculate an approximation of how much data your listbox will store in the worst case : if it’s well below 1GB then you can just do it in RAM; if it’s above, you will need to use the disk-based method.

A second question is whether to do your calculations on the main event loop or in a thread ; a thread will generally be better from the user’s perspective (but more complicated to program).