c++ - Exception when declaring multidimensional arrays


i'm new programming in general , i've run issue declaring 3d , 4d arrays. have several declarations @ start of main function, i've narrowed problem down these 4:

string  reg_perm_mark_name[64][64][64]; short   reg_perm_mark_node_idex[64][64][64]; short   reg_perm_mark_rot[64][64][64][4]; short   reg_perm_mark_trans[64][64][64][3]; 

when run program these, "system.stackoverflowexception" in executable. prefer way allocate them dynamically, way have meant temporary anyway , i'm not sure how declare array pointers properly.

the 4 elements i'm using in 4d array reg_perm_mark_trans, example, [node index][region index][marker index][xyz coordinates]. there's total of 35 multidimensional arrays being declared @ once. (most of them 1d , 2d) i'm not sure if helps.

can show me how make these 4d arrays work or maybe how make them dynamically allocating pointers or vectors? descriptive please, i'm still learning.

assuming simplicity sizeof(string) == 2 (it's more), you're trying allocate (64^3)*9*2 bytes on stack. comes out 4,718,592 bytes, or approximately 4.5 mib. likely, don't have 4.5 mib available on stack.

since these variables declared in main(), have 2 possible solutions:

  1. declare them static.

  2. declare them outside main(), global variables.

this cause them allocated before program starts, rather on stack. difference between 2 approaches whether they'll visible in other functions.

there may way tell compiler program needs more stack space, think making them static better solution here. if in function other main() though, you'd need else.


Comments

Popular posts from this blog

android - Gradle sync Error:Configuration with name 'default' not found -

java - Andrioid studio start fail: Fatal error initializing 'null' -

html - jQuery UI Sortable - Remove placeholder after item is dropped -