I’m a beginner in C++ programming, so please forgive me if this question is somewhat absurd. I am just wondering which approach is better:
1. Upon program start-up, create an array of objects based on data stored in a text file. When the program terminates, the array of objects (and any modifications to it) are written back into the text file.
OR
2. Whenever an object needs to be modified, only that particular object is recreated from the text file, and is written back into the file after modification.
I understand that the 1st approach will consume much more memory than the 2nd, especially when the program is required to work with thousands of objects. However:
• With the 2nd approach, is it safe to open and close the file every time a transaction is made?
• If the 2nd approach is better, then when linked-lists, vectors, etc. should be used?
• Are there any advantages / disadvantages to adopting the 1st or 2nd approach?