Imagine you are simulating particle physics. You, then, have a position vector for each of your objects that is changed at a rate of several times per second. If your vectors are not destroyed but just copied, won’t this cause your program to flood your memory until it ends?
Imagine you are simulating particle physics. You, then, have a position vector for each
Share
I’ll try.
I’ll just assume those are just a handful of abstracted fundamental particles per sim, not terabytes of experimental data.
This is a pretty fundamental question apart from all the context above. The answer is “it depends”.
Is your language garbage collected? What language in particular (no pun intended) is it?
Do you need historical data? Or more generally, what is the reason for not destroying the vectors in the first place? Are all of them still actively used, referenced?
If you need all of them for the sim, i.e. the answer to the above question would be: Yes, but there isn’t much you can do about it. Maybe a) using size-optimized, possibly custom, data and list types and b) if practically applicable – depends on the volatility of the data – applying a pattern that allows you to store only differences (unchanged vectors could be stored as references to the previous version etc.)
If you don’t need them for the running sim, but need to keep them “for later”, just flush them out to disc in large enough chunks as to not waste IO cycles, after that step the same applies as…:
If you don’t need them at all, make sure to allow the garbage collector to work effectively (again, details depend on language used) or free them or re-use the allocated memory etc…
This is a pretty general question and the context you are giving, while it makes you interesting, doesn’t really give us much to go on.