Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>In fact, on windows by default it seems that the default size of the stack allocated for a program is 1MB.</p> <p>But, with your program, when you do <code>PGMImage img</code>, you are allocating a way too much.</p> <p>Explanation :</p> <pre><code>#define MAX 800 // Find it in your link typedef struct {unsigned char red; unsigned char green; unsigned char blue; }RGB_INT; struct PGMstructure { int maxVal; int width; int height; RGB_INT data[MAX][MAX]; }; typedef struct PGMstructure PGMImage; </code></pre> <p>So when you do <code>PGMImage img</code>, you are allocating <em>4 bytes</em> + <em>4 bytes</em> + <em>4 bytes</em> + <em>800 x 800 x 3</em> bytes. It gives <strong>1 920 012</strong> bytes, in other words, almost 2 MB.</p> <p>In cpp :</p> <pre><code>std::cout &lt;&lt; "Sizeof PGMImage : " &lt;&lt; sizeof( PGMImage ) &lt;&lt; std::endl; // gives : "Sizeof PGMImage : 1920012 </code></pre> <p>So it is normal that on windows you get this error.</p> <p>If you want to solve this error :</p> <pre><code>PGMImage* img = (PGMImage*)malloc( sizeof(PGMImage) ); </code></pre> <p>And that's it ! The allocation on the Heap solve this problem, but don't forget to <code>free</code> it at the end !</p> <p><em>A good explanation of the reason of the limit on the stack : <a href="https://stackoverflow.com/questions/2152601/is-there-a-maximum-limit-to-the-size-of-a-variable-that-should-be-allocated-on-a">Is there a maximum limit to the size of a variable that should be allocated on a stack?</a></em></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload