0

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

5
Contributors
19
Replies
20
Views
7 Years
Discussion Span
Last Post by mvmalderen
Featured Replies
  • [QUOTE=nucleon;853418]WH: You're saying that the code below does not crash on your system? [code] #include <iostream> int main() { int matrix[512][512][512]; matrix[0][0][0] = 1; std::cout << matrix[0][0][0] << '\n'; } [/code] Assuming 32-bit ints, that's half a gigabyte! Removing the 3rd dimension works for me, but that's only a megabyte.[/QUOTE] … Read More

  • [QUOTE=nucleon;853429]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 … Read More

0

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

0

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.

0

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.

1

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 :)

Comments
Beware the optimiser reducing the simple program to std::cout << 1 << '\n';
0

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)

0

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).

0

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

0

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

1

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.

Comments
GRATE KNOWLEDGE
0

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

0

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.

0

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.

0

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

0

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 :) ...

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.