I am not here to make their differences, mainly on the use of their attention to some of the problems, mainly reflected in the memory.
In C + +, we rarely use an array of the following, and using an array means assuming:
After the new array, you must ensure that there is a delete to remove the allocated memory. It is best to *p=null the pointer handle. You must use the correct delete, a single object allocates memory using delete, and multiple objects use delete[when allocating memory. An object must be delete only once, and many times an unexpected error occurs. Of course, these are compared to the shortcomings of the array, vector is the advantage of the above is not to consider, but this is not my focus today, it is also very tasty to understand. The problem with a reference count in string is also the focus of this article. For vectors and strings, a similar operation is invoked and realloc whenever more memory space is needed, in 4 steps: Allocating a piece of memory that is a multiple of the current capacity, in most cases twice times. Copy all elements in the container from the old memory to the new memory to remove the old memory from the older memory see here if you think it's tedious, efficiency is not high, that's right, so good things are not enough, especially when these processes occur, all the pointers in vectors and strings, Iterators and references will become invalid, I'm not a good thing. But why do we think they're good. The reserve is the solution to this problem arises. So let's take a look at 4 function size () that tells us how many elements there are in the container, but it doesn't tell us how many elements the container can hold. Capacity () The memory that the container has allocated can hold as many elements as the total number of elements the container can hold. If you want to know how much memory a container can still use, then capacity ()-size () will know. Resize (container::size_type N) forces the container to change to a state containing n elements, and the return value is N. If n is smaller than the current capacity, the element at the end of the container is destructor. Reassigning Memory Reserve (container::size_type N) to force the container to change its capacity to at least n if it is greater than the current capacity, if n is greater than the current capacity to N, or less than, the vector ignores the function directly, and does not call String generally uses swap techniques to achieve memory release. Reference count string reference count for string. Strewn, I went on with my study.