P
P
Pier2010-11-05 15:34:49
C++ / C#
Pier, 2010-11-05 15:34:49

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

6 answer(s)
H
Horse, 2010-11-05
@Horse

What disadvantages have you mentioned?

B
BaJlepa, 2010-11-05
@BaJlepa

I'm sorry
this is better

std::vector<double> v = { 1, 2, 3.456, 99.99 };

R
Rzhepish, 2010-11-06
@Rzhepish

Takes a long time to initialize.

A
Anton Korzunov, 2010-11-06
@kashey

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.

B
BaJlepa, 2010-11-05
@BaJlepa

for example, a couple of years ago it was impossible to initialize with

M
mihaildemidoff, 2010-11-06
@mihaildemidoff

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 question

Ask a Question

731 491 924 answers to any question