Quantcast
Viewing all articles
Browse latest Browse all 22116

Segmentation fault in allocating a large array in C

I intend to allocate a large array of size 1073741824 (equivalent to 1GB e.g.) and then read from it randomly but i get segmentation fault (core dumped) for only defining the array as i checked which i do like:

unsigned int size = 1073741824;short arr = malloc(size * sizeof(short));

i also tried casting it as follows but still the same issue:

unsigned int size = 1073741824;short *arr = (short*) malloc(size * sizeof(short));

also the ulimit command returns unlimited

so what am i doing wrong?


Viewing all articles
Browse latest Browse all 22116

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>