I am using a vector to manage my big data structure. But unexpectedly, upon discovering the source code for vector , I am very surprised to see the following code:
inline void push_back(const _Ty& _X) {insert(end(), _X); } //... void insert(iterator _P, size_type _M, const _Ty& _X) { ////////////////////////////////////////////////////////////// iterator _S = allocator.allocate(_N, (void *)0); iterator _Q = _Ucopy(_First, _P, _S); _Ufill(_Q, _M, _X); _Ucopy(_P, _Last, _Q + _M); _Destroy(_First, _Last); allocator.deallocate(_First, _End - _First); ////////////////////////////////////////////////////////////// }
This is the code for the fragment that destroys and then redistributes all of its vector data. This is so annoying because my structure is large and the vector needs to control hundreds of elements, while I use only vector::operator [] and vector::push_back() , especially pushing back takes up most of my program time ( This is time-consuming). In my case, is there a better container that can work faster than std::vector , and I tried Google, but no luck?
xersi source share