0

I am storing images in memory, so it takes 30mb+ to store it all, (2048*2048 and even more when exporting as .bmp) so I need to increase the stack size. (Or so I read.) The post I read says change the 'Stack reserve size' and 'Stack commit size,' but I don't want to go changing settings like that without really knowing.

I'm dealing with a 2D array of 2048^2 (36mb bytes because it's of type struct with 3 chars in the struct) and when saving it it has a 1D array size of 38000000 bytes to store all things in memory temporarily.

Can someone please tell me how to increase the stack size to this amount?

Bart
  • 19,692
  • 7
  • 68
  • 77
null
  • 548
  • 2
  • 6
  • 17

1 Answers1

2

Don't use a stack-allocated array. This is what you get, for example, in the below code:

void func()
{
 int some_big_array[LOTS_OF_ELEMENTS];
}

Instead, allocate it on the heap. The modern C++ way of doing it is to use std::vector:

void func()
{
 std::vector<int> some_big_vector(LOTS_OF_ELEMENTS);
}

30mb is a small amount of memory for the heap, under common circumstances.

Pradhan
  • 16,391
  • 3
  • 44
  • 59
  • Alright, I'll give it a try, thanks. (P.S., is the vector the same syntax as the stack? Like array[5][67] for example.) – null Apr 04 '15 at 04:26
  • @PaoloMazzon It does not. See [here](http://stackoverflow.com/questions/823562/multi-dimensional-vector), for example. Usage has the same syntax as the array. However, declaration does not. Additionally, if you are using C++11, you can initialize multi-dimensional vectors like you would arrays. – Pradhan Apr 04 '15 at 04:27
  • EDIT: This is the third time I've got the vector thing just dropped on me. Please, can you explain the vector, how to use it, etc... I find it really annoying when I ask a question on this site (Great site) and people just drop some syntax and say "do it." (Exaggerated) I'm using 2D arrays and I have absolutely no clue what to do about a 2D vector. – null Apr 04 '15 at 04:36
  • I am afraid the question about using 2D vectors is too broad for me to answer at the moment. Please go through the answer I linked to and perhaps read a tutorial with examples. You are more likely to get better answers the more specific your questions get. – Pradhan Apr 04 '15 at 04:45