Quote:data on the stack in main() - in which case you need to switch to allocating some data elsewhere (I.e. on the heap)
what do you mean, can someone detail this a bit.
Quote:data on the stack in main() - in which case you need to switch to allocating some data elsewhere (I.e. on the heap)
Quote:Original post by CalinEvery local variable takes up some stack space (And every member variable in every class you have instanced as a local variable). On Windows by default you have 1MB of stack. If all of your local variables total more than 1MB, you'll get a stack overflow.Quote:data on the stack in main() - in which case you need to switch to allocating some data elsewhere (I.e. on the heap)
what do you mean, can someone detail this a bit.
Quote:Original post by LessBreadchkstk (check stack) is a compiler intrinsic function that "touches" stack pages to ensure they are paged in before they are used. On Windows, the default size of the stack is 1 mb, but all of that memory is not paged in at the outset. The compiler inlines the chkstk function when it encounters stack variables (ie local function variables) larger than one page. eg array[128][128]. If that was an array of char, it would require 16kb or 4 pages (1 page == 4096 bytes). With a name like vertices, I suspect the size of each element of the array is a lot more than one byte. At any rate, chkstk, advances the stack pointer page by page, "touching" each page as it proceed through a loop counting down the number of pages the variable requires. It makes sense that the stack overflow exception lands in chkstk, because the "touching" instruction produces the fault when the stack pointer has gone beyond the stack limit.
Quote:I have an array of 256x256
color LightMap[256][256]; (each color has 4 ints) Is this is too big how do I solve it?
Quote:
I don't think the array is that big, it should be able to fit on the stack. But you could try allocating it on the heap to be sure, just make sure you 'delete[]' it after using it.
Quote:
How do you allocate on heap?
int *blah = new int[4][4];
delete [] blah;
Quote:Original post by CalinQuote:
I don't think the array is that big, it should be able to fit on the stack. But you could try allocating it on the heap to be sure, just make sure you 'delete[]' it after using it.
How do you allocate on heap?
int *blah = new int[4][4];
delete [] blah;
Quote:Original post by Chadwell
Not quite. A multidimensional array on the heap is actually an array of arrays, and thus the array must contain pointers to point to those arrays.
int (*a)[4] = new int[4][4];delete[] a;
typedef int row[4];row *a = new row[4];delete[] a;
Quote:Original post by Calin
It feels almost like a sin not being able to declare large array without pointers.
std::vector<int> large(10000000); // 40 MB of fresh memory initialized to 0
Quote:Original post by Calin
Why do I access member variables through pointer as if _MyX is a regular varibale? _MyX[10].y = 10; (instead of using the -> sign)