I have a general wondering about std::vector<string>.

If you declare something like this, I have set 1 million elements to this vector.
If I run this program just declare it like this without filling the elements with any strings.
Does this take up any RAM memory just because I have declared this number of elements or do I have to fill them up to take up RAM.

Then I do wonder how many MB is 1000000 (1 million elements) ?

std::vector<string> vec(1000000);

Recommended Answers

All 2 Replies

>>Does this take up any RAM memory just because I have declared this number of
>> elements
Yes -- it will take up (1000000 * sizeof(string)) + sizeof(vector) before any of the strings have been initialized with anything.

okay, then I know better how to think when I declare vectors. thank you.

>>Does this take up any RAM memory just because I have declared this number of
>> elements
Yes -- it will take up (1000000 * sizeof(string)) + sizeof(vector) before any of the strings have been initialized with anything.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.