Are variable dimensional arrays distributed across static or stack produced in heap space?

It may not be platform dependent, but I will fix it in Win 10 GCC anyway.

Suppose you create an array or vector consisting of elements, each of which can have a variable size, in a static memory space in main ():

RADIAL_UNITS = 1000000;
static vector<Pearl> necklace[RADIAL_UNITS] = { }; 
//each element is a variable-sized vector, which can consist of anywhere from 1-50 Pearl objects 

or allocated on the stack in main () (assuming that the stack space has a resolution of at least 1,000,000 memory addresses):

vector<Pearl> necklace[RADIAL_UNITS] = { }; 

I assume that at runtime it necklaceconsists of RADIAL_UNITScontiguous memory addresses, pointing to elements vector<Pearl>. What I don’t understand is in (i), in what memory space the elements of the vector are (I suspect a lot of space) .

Side questions that interest me:

(ii), , . STL - , ? , , , ( , .. , , segfault, ), (iii) , 50*sizeof(Pearl), , ? , .

+4
1

, vector

, vector ( ), vector , "".

, , . [...] , , , .

vector . "" , . .

, 50*sizeof(Pearl)

vector, array :

static array<Pearl,50> necklace[RADIAL_UNITS]; 
+5

Source: https://habr.com/ru/post/1682606/


All Articles