OBJECTIVE: manage a unsigned long tomBOLA[5][10000000];
$top
gives me:
top - 14:05:35 up 4:06, 4 users, load average: 0.46, 0.48, 0.44
Tasks: 182 total, 1 running, 180 sleeping, 1 stopped, 0 zombie
Cpu(s): 14.4%us, 2.4%sy, 0.0%ni, 82.5%id, 0.6%wa, 0.0%hi, 0.0%si, 0.0%st
Mem: 3092064k total, 1574460k used, 1517604k free, 168944k buffers
Swap: 1998840k total, 0k used, 1998840k free, 672756k cached
program has, a malloc the size of (5*10000000) * 8bytes =382MB, then fill with 0s and a read of what is stored in tomBOLA:
long int **tomBOLA;
if((tomBOLA=(long int **)malloc(5))==NULL){ /*MALLOC()*/
printf("\n\tMEMORY ERROR-1");
exit(1);
}
for(i=0;i<5;i++){
if((tomBOLA[i]=(long int *)malloc(10000000*sizeof(long int)))==NULL){
printf("\n\tMEMORY ERROR-2");
exit(1);
}
} /*MALLOC()*/
for(i=0;i<5;i++){
for(j=0;j<10000000;j++){
tomBOLA[i][j]=0;
}
} /*FILL WITH 0s before using*/
for(i=0;i<5;i++){
for(j=0;j<10000000;j++){
printf("%ld ",tomBOLA[i][j]);
}
printf("\n\n\n\n\n");
} /*CONTROL OF 0s*/
gdb gives
Program received signal SIGSEGV, Segmentation fault.
_int_malloc (av=<value optimized out>, bytes=<value optimized out>) at malloc.c:4708
4708 malloc.c: No such file or directory.
in malloc.c
(gdb) bt
#0 _int_malloc (av=<value optimized out>, bytes=<value optimized out>) at malloc.c:4708
#1 0x001dfd4c in *__GI___libc_malloc (bytes=40000000) at malloc.c:3660
#2 0x0804ca86 in main ()
(gdb)
about memory, what am i doing or assuming wrong ??