What data structure to use

I am looking for a suitable data structure for this scenario. I have the opportunity to use.

The code was originally in C #, and I used the queue there, but I do not think that it was a suitable choice, and, as far as I can tell, there is no C ++ equivalent for the C # queue. I consider the following properties in terms of their frequency / importance:

  • Faster Iteration Required
  • You must be able to quickly advance the structure (i.e. when I pull an element from above, the next element should be a structure)
  • Will be cleaned sometimes and then completely populated
  • Will be copied from time to time
  • No need to sort, as items will be added in the correct order.

The number of elements will be known at creation time and will be between 50 and 200 elements. A structure will never contain more than that, but may sometimes contain less

I considered using std :: list, but with the need to clear and then re-populate, this does not seem to be a good option. When I create a list with a fixed size, then clear it, it loses the prefix size, right? Is there a way to keep the list size so as not to free / allocate memory?

I know that boost has a queue data structure, but it is not iterable, and I'm not sure if it will have the same problem that I have with std::list

Some suggestion on how to embed std::listin my problem or a more suitable data structure would be helpful.

+3
source
3
+10
+2

A ring buffer (implemented as a static array Foo buffer[200]and two counters), as suggested by eevar, would be better. No need for STL / Boost.

-3
source

All Articles