+ 1

Which approach to loading data used by program from a file is better?

I would like to know your opinion on following problem. Imagine you have a program which uses data stored in a text file (say in an XML file) in some folder (e. g. \data\...data.xml). I suppose two approaches: 1. you load the whole file at program startup or 2. you pull particular pieces of data when they are needed while program is running. The same question I have about saving to such file when the data was changed - is it better to save separate pieces "on the fly" or all at once (e. g. on termination of the program)? Which one is more correct (from the point of view of memory management and performance)? Maybe there are some other ways to load data? Feel free to suggest.

16th Oct 2017, 6:16 PM
Asch
Asch - avatar
1 Resposta
+ 2
This question doesn't have a definite answer. The best approach depends on how big is the data/how much memory we can afford to use and how intensive the data usage will be. It's an ubiquitous trade-of of speed/bandwidth vs space. The same applies to working with data over network. But, in case of working with xml, the program needs at least to know the schema of the file it's working with to be able to navigate the DOM, and also searching through the xml file contents is quite resource heavy. So, IMO, in most cases, it's better to load the xml to the more "navigatable" data structure in memory.
16th Oct 2017, 6:54 PM
deFault