memory management - How to declare and use huge arrays of 1 billion integers in C? -


i'm implementing sequential program sorting quicksort. test performance of program in huge array of 1 or 10 billions of integers. problem obtain segmentation error due size of array.

a sample code of declaration of array:

#include <stdio.h> #include <stdlib.h> #include <time.h> #define n 1000000000  int main(int argc, char **argv) {   int list[n], i;   srand(time(null));   for(i=0; i<n; i++)      list[i] = rand()%1000;   return 0; } 

i got proposition use mmap function. don't know how use ? can me use ?

i'm working on ubuntu 10.04 64-bit, gcc version 4.4.3.

thanks replies.

michael right, can't fit on stack. however, can make global (or static) if don't want malloc it.

#include <stdio.h> #include <stdlib.h> #include <time.h> #define n 1000000000 int list[n];  int main(int argc, char **argv) {   int i;   srand(time(null));   for(i=0; i<n; i++)      list[i] = rand()%1000;   return 0; } 

Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -