Fwd: Re: Is there heap size limitaion?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Thank you for your help. I used sizeof(int *) and it worked.

#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <time.h>
int main()
{

int i, j;

int **table1=malloc(10000000*sizeof(int*));
int *table1_aux=(int *)malloc(10000000*100*sizeof(int));
for (i=0; i<10000000; i++) table1[i]=table1_aux+i*100;
for (i=0; i<10000000; i++) {
for (j=0; j<100; j++) {
         table1[i][j]=0;
}
}
printf("table1 ok\n");

int **table2=malloc(10000000*sizeof(int*));
int *table2_aux=(int *)malloc(10000000*100*sizeof(int));
for (i=0; i<10000000; i++) table2[i]=table2_aux+i*100;
for (i=0; i<10000000; i++) {
for (j=0; j<100; j++) {
         table2[i][j]=0;
}
}
printf("table2 ok\n");

return 0;
}

--- Begin Message ---
Alexey Salmin wrote:
>> ^ This is wrong.  Should be
>>
>>  int **table1=malloc(10000000*sizeof(int**));
>>
>> The same error occurs several times.
>>
>> You also need
>>
>>  if (!table1 || !table1_aux)
>>    perror ("");
>>
>
> LOL, you've got to be kidding us :)
> "table1" is pointer to an array of (int *). That's why it has type (int **).

Sorry, thinko: sizeof(int*).  Not that it will make any difference, of course.
The change from sizeof(int) to sizeof(int *) is still needed.

Andrew.


--- End Message ---

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux