Is an array of vectors a completely continuous memory?

I know that vectors are guaranteed to be continuous memory, as well as arrays. So what happens when I do something like this:

std::vector<uint8_t> my_array[10];
my_array[2].push_back(11);
my_array[2].push_back(7);

What will the memory look like? If both should be contiguous, will each element of the array after being my_array[2]pushed forward by byte every time I do push_back()on my_array[2]?

Will the situation be the same as when I have an array of structures where the structures have a variable size member, like a string or another vector?

+4
source share
2 answers

The memory std::vectorcapacity consists of two parts:

  • std::vector ( )
  • ( ).

; , .

, C struct, , std::vector , , . , , . , , .

, push_back, std::vector . , , .

+5

; std::vector , ( , ).

, std::vector:: push_back , () , . Push_back , , , , , .

, , , .

std::string , , , (, ) char*, .

+3

All Articles