malloc fails for 5×10^8 doubles on 8GB Windows system

  • Thread starter Thread starter nenyan
  • Start date Start date
  • Tags Tags
    Suggestions
Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
1 reply · 3K views
nenyan
Messages
67
Reaction score
0
Code:
#include <stdio.h>
#include <stdlib.h>
#define N 250000000

int main()
{
    int i; 
    double *x;

    if(!(x = malloc(N * sizeof(double)) ))
            printf("memory error \n");

free(x);
}
When N is larger than 2.5*10^8, it appears memory error. I have 8GB memory. The system is Windows7. How to solve this problem. I hope N=5*10^8 at least.
 
Physics news on Phys.org
A 64-bits compiler will probably help.
As it is you are overrunning the range of a 32-bits integer.