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

Recommended Answers

[QUOTE=nucleon;853418]WH: You're saying that the code below does not crash on your system?
[code]

include

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 …

Jump to Post

[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 …

Jump to Post

All 19 Replies

Re: Int matrix[512][512] 80 80

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

Re: Int matrix[512][512] 80 80

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

Re: Int matrix[512][512] 80 80

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.

Re: Int matrix[512][512] 80 80

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

Re: Int matrix[512][512] 80 80

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

Re: Int matrix[512][512] 80 80

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.

Re: Int matrix[512][512] 80 80

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
Re: Int matrix[512][512] 80 80

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)

Re: Int matrix[512][512] 80 80

WH: What are your system specs and compiler?

Re: Int matrix[512][512] 80 80

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

Re: Int matrix[512][512] 80 80

WH: What are your system specs and compiler?

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

Re: Int matrix[512][512] 80 80

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

Re: Int matrix[512][512] 80 80

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

Re: Int matrix[512][512] 80 80

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
Re: Int matrix[512][512] 80 80

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

Re: Int matrix[512][512] 80 80

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.

Re: Int matrix[512][512] 80 80

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.

Re: Int matrix[512][512] 80 80

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

Re: Int matrix[512][512] 80 80

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.19 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.