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
booker 0 Newbie Poster
Recommended Answers
Jump to Postdepends on the compiler and operating system. most likely that matrix is overrunning stack space.
Jump to PostIt'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 …
Jump to PostBoth compiled fine for me, in fact, even
int matrix[512][512][512];
compiled and ran fine for me.
Jump to PostWH: 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 …
Jump to Posttux> 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 …
All 19 Replies
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
booker 0 Newbie Poster
William Hemsworth 1,339 Posting Virtuoso
tux4life 2,072 Postaholic
William Hemsworth 1,339 Posting Virtuoso
nucleon 114 Posting Pro in Training
William Hemsworth 1,339 Posting Virtuoso
Salem commented: Beware the optimiser reducing the simple program to std::cout << 1 << '\n'; +29
tux4life 2,072 Postaholic
nucleon 114 Posting Pro in Training
nucleon 114 Posting Pro in Training
William Hemsworth 1,339 Posting Virtuoso
booker 0 Newbie Poster
booker 0 Newbie Poster
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
booker commented: GRATE KNOWLEDGE +1
booker 0 Newbie Poster
booker 0 Newbie Poster
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
booker 0 Newbie Poster
tux4life 2,072 Postaholic
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.