title: How to change heap and stack memory size in GCC 4.6.3?
body: <p>While using malloc I have noticed that the pointer assigned is null. I want to allocate much more memory around 30 MB to the heap memory during execution of the code. How can I do so on Ubuntu 12.04 LTS with GCC 4.6.3 used as a compiler?  Should I allocate more stack memory instead? Would it be better?</p>
  
  <p>Thanks</p>
  
  <p>Edit the problematic part of the code, the code is terminated after the if statement.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;math.h&gt;
  #include &lt;limits.h&gt;
  #include &lt;stdlib.h&gt;
  #define a0 0.53 
  #define N LONG_MAX
  // This value of N is the highest possible number in long double
  // data format over 100. Higher is not possible due to the size of 
  // the default heap memory. Change its value  to adjust the precision of 
  // integration and computation time. Since exponential decays really fast
  // a modest value of N is enough for this integration.
  // The discrete integral may be defined as follows:
  long double trapezoid(long double x[],long double f[]) {
    int i;
    long double dx = x[1]-x[0];
    long double sum = 0.5*(f[0]+f[N]);
  
      for (i = 1; i &lt;  N; i++) 
          sum+=f[i];
    return sum*dx;  
  }
  main() {
      printf("LONG_MAX constant has the following value: %ld \n", LONG_MAX);
      long double * P = malloc(N * sizeof(long double));
      long double * r = malloc(N * sizeof(long double));
      long double * PP = malloc(N * sizeof(long double));
      // The if statement is to check if the memory allocation has 
      // been done and terminate the program otherwise.
      if (P == 0 || r == 0)
          {
              printf("ERROR: Out of memory\n");
              return 1;
          }
      // Declare and initialize the loop variable
  }
  </code></pre>