C++ Vector initial capacity

The capacity of a vector cannot be controlled by the constructors – there is no applicable overload.

The C++ standard doesn’t give any guarantee about the capacity of a default-constructed vector vector<Foo> bar;. However all well-known implementations use 0 as the default capacity. This is something you can rely on, as allocating memory at that point just doesn’t make sense.

So I believe the answer to your question is: just use

vector<Foo> bar;
bar.reserve(4);

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)