c++ - std::vector insert() reallocation -


I was looking through the std :: vector code and I think I did not find much. When the capacity & lt; Size () + 1 is required to allocate buffer again, so this new element can be inserted What does this (as far as I am able to remove from the code) is:

  • Make a new element in the new buffer
  • Old buffer (index end) )
  • Call old buffer
  • Prefix and Copy of suffix as a copy I can see that it is done with memmove. Does not remember a pure binary copy of the data? It does not call the constructor of the elements, right? I was wondering, why the function is on the elements present in the old buffer Tells to the Destructor, if the memory is gone, has not been created again in the new buffer?

I am using MSVC 8 vector mean of implementation Saw - I can not see memmove () . The last vector elements are not transferred, they are copied and their copy is called to copy them to the new buffer (buffer) Is allocated in an allocation, elements are constructed using appointments).

Of course this is only MSVC implementation, but it should behave according to a vector standard.

However, using memmove is sometimes correct - for example std :: vector & lt; Int & gt; - and are the experts for the implementation of STL. You may have missed a template 'branch' reading source code.


Comments

Popular posts from this blog

oracle - The fastest way to check if some records in a database table? -

php - multilevel menu with multilevel array -

jQuery UI: Datepicker month format -