Reputation: 479
Gang, I need some ideas on this one.
Let's say I want to build a CSV file from data I collect. The data is about 100MB in a List. Is it more efficient to build the List first and then write the whole List to the CSV or should I write to the CSV as I collect the data?
Thanks in advance.
Upvotes: 0
Views: 140
Reputation: 68
It seems that you are asking specifically about efficiency.
If you define most efficient by total memory allocated - then certainly build the CSV as you get the data.
If you define most efficient as the method with the most versatility in utilizing the data in the (short term) future, then maybe populating the list first is most prudent.
There are a number of other posibilities, I guess it depends on how you define efficiency.
Upvotes: 1
Reputation: 6536
It will be faster to not use any memory and use it as a list, but, if you're doing operations in which you need to consider slices of the data, it will be far easier and maybe faster to use the list.
Upvotes: 0