This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Question about setting appropriate stack and heap size

Hello:

   Yesterday, I defined a 2-D vector with size 20*10 and my stack and heap size was the defaul value 0x400:

 

 

   

 

And I found that if I increase the size from 20 to 21 or 10 to 11, the system error occured.

 

Then I reset the stack and heap size as 0x5000 and 0x5000, I can define even vector[65][28] without error.

 

My confusion is that why the vector size has close connection with the stack and heap size?

If I want to create a very big matrix like vector[1000][100], I want to reset stack and heap size as 0x10000 and 0x10000 then the system refused me to set to this large value by reporting errors.

How to deal with this problem if I want to set a extremely large-sized vector?

 

Thank you

 

Yu

 

  • Yu Zhang39 said:

    My confusion is that why the vector size has close connection with the stack and heap size?

    Local variables within a function that are not declared "static" are typically stored on the stack. That is the reason that as your vector size increases the amount of stack required will also increase. On the other hand, global variables and function level static variables are stored in the .ebss section (you can take a look at that section in the linker command file and link map file), so you could try making the variable global to reduce stack usage.

    This wiki page might also be helpful: http://processors.wiki.ti.com/index.php/Stack_and_Heap_size_requirements