I'm looking for the proper data structure for this scenario. I have boost available to use.
The code was originally in C#, and I was using a queue there, but I don't believe that was an appropriate choice, and there isnt a C++ equivalent for C#'s queue as far as I can tell. I'm looking at the following properties in terms of their frequency/importance:
The number of elements will be known at creation time and will be 50 to 200 elements. The structure will never hold more then this, but may occasionally hold less
I was considering using std::list, but with the need to clear then repopulate occasionally, this doesn't seem to be a good option. When I create a list with a fixed size, then clear it, it loses the prefixed size doesn't it? Is there some way to always keep the list size so it doesn't have to deallocate/allocate memory?
I know boost has a queue data structure, but it isn't iterable, and I'm not sure if it would have the same problem I had with std::list
Some suggestion on how to fit std::list into my problem or a more appropriate data structure would be helpful.
std::deque seems to meet all of your requirements.
If performance is a real issue for you, you should read GMan's answer to Pre-allocate space for C++ STL queue .
Sounds like a ring buffer should work? There is one in boost: boost::circular_buffer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With