Hello
is this normal that the application I am running crashes when I try to instantiate e initialize a int matrix[512][512] where for smaller values doesn't?
I just can't understand why. I could create I vector of vector but I want to use a pointer pointing to Aoo.
Thank you

depends on the compiler and operating system. most likely that matrix is overrunning stack space.

Do you think I would have the same problem if I use a vector instead?
Do you know how to overcome this problem?

It's not surprising your program crashes, it's the same as making an array with a size of: 512 * 512 = 262144 elements, or 1048576 bytes. As Ancient Dragon said, you don't have enough stack space.

>Do you think I would have the same problem if I use a vector instead?
A vector allocates dynamic memory, so it will only work if you have enough free dynamic memory - which it should have.

>Do you know how to overcome this problem?
If dynamic memory doesn't work, which I think it will, there's probably another way to approach the problem without having to allocate so much space.

With me using a vector worked and int matrix[512][512]; didn't (but it still compiled correctly :))

Both compiled fine for me, in fact, even int matrix[512][512][512]; compiled and ran fine for me.

WH: You're saying that the code below does not crash on your system?

#include <iostream>
int main() {
    int matrix[512][512][512];
    matrix[0][0][0] = 1;
    std::cout << matrix[0][0][0] << '\n';
}

Assuming 32-bit ints, that's half a gigabyte! Removing the 3rd dimension works for me, but that's only a megabyte.

WH: You're saying that the code below does not crash on your system?

#include <iostream>
int main() {
    int matrix[512][512][512];
    matrix[0][0][0] = 1;
    std::cout << matrix[0][0][0] << '\n';
}

Assuming 32-bit ints, that's half a gigabyte! Removing the 3rd dimension works for me, but that's only a megabyte.

Works flawlessly :)

commented: Beware the optimiser reducing the simple program to std::cout << 1 << '\n'; +29

WH: You're saying that the code below does not crash on your system?

#include <iostream>
int main() {
    int matrix[512][512][512];
    matrix[0][0][0] = 1;
    std::cout << matrix[0][0][0] << '\n';
}

Assuming 32-bit ints, that's half a gigabyte!

If your computer has more than a GB of RAM that wouldn't be a problem I think :) (it may also depend on which compiler he's using)

WH: What are your system specs and compiler?

tux> If your computer has more than a GB of RAM that wouldn't be a problem

But the OPs computer crashed with just a megabyte-sized array. :( So it's not about total space available, but about how much stack space is reserved (which of course can be increased with a compiler option).

WH: What are your system specs and compiler?

I use VS2005 professional. 2gb ram, running 32-bit Windows Vista.

WH: What are your system specs and compiler?

I am running XP over MacBook with 1GRam allocated for XP and 1G for Mac. It is 32-bits system

I run XP over Mac with 1GB allocated for XP and 1G for Mac. I also use VC++ as IDE

tux> If your computer has more than a GB of RAM that wouldn't be a problem

But the OPs computer crashed with just a megabyte-sized array. :( So it's not about total space available, but about how much stack space is reserved (which of course can be increased with a compiler option).

You are right. My computer has 8 gig RAM, compiled with VC++ 2008 Express, and it crashed when I ran it.

commented: GRATE KNOWLEDGE +1

Thank you dragon. i have to check how to increase the vc++ compiler stack space now.

Dragon you are grate!!!thanks to all of you. i lost 1 day, but i learned something new i never know about setting the linker's option for the stack overflow.

Well, not so fast. I solved the stack problem by changing one of the Link options, but the program still will not run. The os won't even start it.

No it works fine...i googled how to set the stack with vc++ and thats all.bye

tux> If your computer has more than a GB of RAM that wouldn't be a problem

I tried this on a computer with 1.5GB RAM, it compiled and ran without crashing, I tried to put a value in the array, that did also work, but displayin that value: result was just nothing :) ...