Is there heap size limitaion?

Andrew Haley aph@redhat.com
Mon Jan 5 10:53:00 GMT 2009


Anna Sidera wrote:
> 
> ----- Original Message -----
> From: Andrew Haley <aph@redhat.com>
> Date: Friday, January 2, 2009 11:50 am
> Subject: Re: Is there heap size limitaion?
> 
>> Anna Sidera wrote:
>>> From: Andrew Haley <aph@redhat.com>
>>>> Anna Sidera wrote:
>>>>> -----  -----
>>>>> From: Andrew Haley <aph@redhat.com>
>>>>>> Anna Sidera wrote:
>>>>>>> Can you tell me if there is heap size limitation in gcc? I 
>> use 
>>>> a 
>>>>>> server with 4 CPU and 16 BG ram. I create tables using malloc 
>>>> and 
>>>>>> the total memory I can use is a little less than 4 GB.
>>>>>>
>>>>>> Seems odd.  What OS / architecture are you using?
>>>>> I am using unix. SunOS 5.10
>>>> OK, but what architecture?  32-bit or 64-bit mode?
>>>>
>>>> Type
>>>>
>>>> isainfo -v
>>>>
>>>> If it's 32-bit then you will be limited, obviously.
>>>> If gcc is generating 32-bit executables then you will also be
>>>> limited.  The -m64/-m32 options control this.
>>> isainfo -v gives the following output:
>>>
>>> 64-bit sparcv9 applications
>>>         vis2 vis
>>> 32-bit sparc applications
>>>         vis2 vis v8plus div32 mul32
>> So, did compiling with -m64 fix it?
>>
>> Andrew.
>>
>>
> -m64 did not work. For the following program if I use -m32 the fist printf statement works but before the second one I get core dump. If I use -m64 I get core dump before the first printf.
> 
> #include <stdio.h>
> #include <math.h>
> #include <stdlib.h>
> #include <time.h>
> int main()
> {
> 
> int i, j;
> 
> int **table1=malloc(10000000*sizeof(int));

^ 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 ("");


> 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;
> }
> 
> Anna
> 



More information about the Gcc-help mailing list