How to pick a container.

I'm not exactly sure what a best practice is for picking a container but I figured I'd ask for some general advice here!

Lets say I wanted to read lines of information from a file into a container for comparison to set values.

Would it be better to:

Option A

Use a fixed length static array and clear the values in the container before each line is read from the file then written to the array.


Or Option B

Use a dynamic array or vector and delete the container before each line is read and create the container again for the new information to be written into.


I guess I could do some testing on my own but not even sure how to start benchmarking stuff. Any suggestions on benchmarking code or even good strategies/guide lines to follow for figuring out optimal solutions.
closed account (Dy7SLyTq)
i guess you could call an array a sort of built in container, but i dont typically associate with that. and i would only use a static size array when you know the size before hand, for example a prompt or a collection of response codes or binary op codes. as to the dynamic container it really depends on what you want to do. if you want to make a waiting room, i would use something like a stack or a queue. if you wanted to make something that wont require a lot of iteration, a list. if you wanted direct access vector
Thanks for the suggestion, i think a stack or a queue was the idea I was searching for.

I will play around with those some.
Topic archived. No new replies allowed.