I recent wrote this post:
How best to store VERY large 2D list of floats in c++? Error-handling?
Some suggested that I implemented my 2D list-like structure of floats as a vector, others said a deque.
From what I gather vector requires continuous memory, but is hence more efficient. Obviously this would be desirable if possible.
Thus my question is what’s a good rule of how long a basic structure can be in terms of…
1. float
2. int
…before you should switch from a vector to a deque to avoid memory problems?
e.g. I’m looking for answer like “At around 4 million floats or 8 million ints, you should switch…” …if possible.
There are so many factors to consider that it’s impossible to give a clear answer. The amount of memory on the machine, how fragmented it is, how fragmented it may become, etc. My suggestion is to just choose one and use it. If it causes problems switch. Chances are you aren’t going to hit those edge cases anyway.
If you are truly worried, then you could probably implement a sort of pseudo PIMPL:
But this seems like total overkill. Have you done any benchmarking or tests? Do you have any reason to believe that memory allocations will fail or that deques will be too slow?