Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Please give me some suggestions about malloc

  1. Dec 12, 2011 #1
    Code (Text):

    #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.
     
  2. jcsd
  3. Dec 12, 2011 #2

    I like Serena

    User Avatar
    Homework Helper

    A 64-bits compiler will probably help.
    As it is you are overrunning the range of a 32-bits integer.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Please give me some suggestions about malloc
  1. Please help me (Replies: 3)

  2. Malloc in C (Replies: 6)

Loading...