I'm having a problem deciding which container would be best for me for my purposes.
I'm currently working on a particle engine using C++ and SDL's primitive shape functions, everything's working pretty good, and I've been using a vector so far, but when I get to around 700 particles, the game starts to give really big pauses between frames, tracing down using the console and cout messages brought me to the conclusion that the arson is the erasing method I use for outdated particles.
Particles on this engine have a certain uptime since creation, and once that is up, they are to be deleted like so:
for(unsigned int i = 0; i < parList.size(); ++i){
if(SDL_GetTicks() - parList.start >= (Uint32)parList[
i].time){
parList.erase(parList.begin()+i);
--i;
}
}
Problem is, the erase method of a vector is not random acess, to my understanding, and once the time comes for it to kick in, if the number of particles it should be deleting at one time is too big, it will hang the program(The noticable number this will start happening at is 40).
Trying to switch to a container that had better performance for erasing elements, I went back to a list, but then remembered that iterating through 700 objects on a list is even worse practice here.
I tried looking up a bit on Google, but actually defining this question with a sum of words isn't really simple and gave no useful results.
So I'm turning to the experts here in the question, which STL container is best suited for constant iteration of the container(With no need for random access) AND random element erasing with the best performance?
Which container is typically used to manage particles in other games?
Thanks alot for the help to come!