Let me explain a little background of the situation in case there is a wiser solution than vectors. I've got a loop running in a program, and for each loop, I need to add a new element at the end. I need to backtrack anywhere from 5 - 250 elements. The amount I need to backtrack does not remain constant throughout the program. The problem(I think) is that after a while, it would just keep allocating memory when I don't need it. At a certain point, I want to delete the first element, freeing that memory space up.

My first thought was to use a vector, but I'm not sure if there is a way to do what I want. I looked through some reference material and I found vector::resize , but it sounds like if I want to restrain it, it deletes elements at the end instead of the first elements. I'm not totally familiar with all of the STL containers, so maybe another one would suit it better. Any ideas or suggestions?

11 Years
Discussion Span
Last Post by Lerner

You might want to look into deque. It is basically a vector that has been modified to facilitate ease of deletion from front end operations. Deques are useful when you want to allow insertion or deletion at either end of the structure and you also want sequential access of elements.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.