I have a piece of performance critical code written with pointers and dynamic memory. I would like to rewrite it with STL containers, but I m a bit concerned with performance. Is there a way to increase the size of a container without initializing the data?
例如,不这样做
ptr = new BYTE[x];
我想做的是这样的事情。
vec.insert(vec.begin(), x, 0);
However this initializes every byte to 0. Isn t there a way to just make the vector grow? I know about reserve() but it just allocates memory, it doesn t change the size of the vector, and doesn t allows me to access it until I have inserted valid data.
谢谢大家。