Thanks for all these replies. So I looked through some code on a few projects that I am working on for where I could use array instead of vector. For my use I only found 4 places where I am using a vector with a fixed number of elements.
So I guess I should have suggested to the OP that an array was fine is he just had the 4 clouds and wasn’t going to have more or dynamically add them, etc.
Thanks for the lesson today! We all benefit from conversations like this.
Yeah. I just makes no sense using a dynamic container, if you don’t need it. They offer a lot of features, memory management and what not, you just don’t need anyway. It just wastes resources. This is not so important with all that CPU power today, but maybe if you are using embedded devices or need thread safe containers or concurrency.
There are only a few containers and scenarios, which are thread-safe.
The problem with the containers are the iterators. They are invalidated if you are modifying the container elements. E.g. thread 1 changes elements, while thread 2 iterates over them. You would need some locking on the container.
The containers implement different allocators, which have to be adopted to concurrency. It is not an easy task.
Dynamic containers are reallocated, when inserting elements. This is a problem, if thread a is writing into the container(and the container needs reallocation), but thread 2 iterates over the container. Pointers and memory addresses are invalidated at the reallocation, so you have to compensate for it.
If the threads just do read operations on the container, you don’t have a problem.
There are different implementations of the STL, which differ in thread-safety.
You can read about thread-safety and containers here:
I had access to the standards years ago.
If i need to quote something here and then, I just use the pdf versions of the drafts.
Search it? Just produce the pdfs or use the links in here: