Answer the question
In order to leave comments, you need to log in
What is the main disadvantage of std::vector?
What is the main disadvantage of std::vector?
I was asked this question a couple of years ago in an interview. I listed several disadvantages, but, in the opinion of the interviewee, I did not name the main disadvantage. Several years have passed, but I have not “invented” the answer to this question. Or was it a trick question?
Answer the question
In order to leave comments, you need to log in
I'm sorry
this is better
std::vector<double> v = { 1, 2, 3.456, 99.99 };
The main disadvantage of a vector is reallocate .
This is exactly what the main one, I would even say the root one, but you can create it with a pre-exceeded size. Often helps.
That he had a long initialization - did not even know - nedmalloc (and company) will save the fathers of Russian democracy.
for example, a couple of years ago it was impossible to initialize with
If we compare vector with a regular array, then, in my opinion, there are 2 main drawbacks:
1) The speed of vectora as a whole
2) The amount of memory occupied compared to a regular array
Of course, in some cases these things can be neglected, but somewhere it can be very critical. Also, everything naturally depends on the directness of the hands of the programmer, since mastering the STL as a whole requires considerable knowledge and skills.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question