DEV Community

Efficient way of using std::vector

Adam Sawicki on September 22, 2018

Some people say that C++ STL is slow. I would rather say it's the way we use it. Sure, there are many potential sources of slowness when using STL....
Collapse
 
zhu48 profile image
Zuodian Hu

Another fun way STL containers can be misused is not understanding the underlying memory management enough. Growing an std::vector by naively pushing elements and letting the container grow automatically is much, much slower than pre-allocating if you know the roughly how large your data set will be.

Collapse
 
reg__ profile image
Adam Sawicki

That's right, I fully agree.