Mail Archives: djgpp/1997/10/15/15:46:14
In article <Pine DOT GSO DOT 3 DOT 94 DOT 971012124635 DOT 6579A-100000 AT minerva DOT cis DOT yale DOT edu>, "J. Hormuzdiar" <jimh AT pantheon DOT yale DOT edu> writes:
> Hello-
> Perhaps this question is better intended for comp.lang.c, but I am
> not sure yet.
>
> I am using a djgpp/rhide environment with a program that has some
> huge fixed size arrays. When I compile I get an executable that is
> correspondingly huge (many meg's), even though the code is pretty small.
> I assume that the compiler is saving the whole huge blank pre-used array
> in the executable, and I wish it wouldn't. The space is a problem, but
> even worse is the wait for the compiler to save the huge thing every time.
>
> I could just dynamically allocate using malloc, but I seem to
> remember that there is a keyword or option that will automatically do it
> for me. Perhaps I could just add a word to the declaration-
>
> (word) float x[7000][7000];
>
> Thanks for your help.
>
> -Jim
>
>
--
Fixed arrays are allocated in the program space.
To make the program smaller either move the array into main
or dynamically allocate it using malloc / new, like this
float **x;
void main(void)
{
x=(float**)malloc(7000*7000*sizeof(float)); /* Allocate memory */
if (x==NULL) /* Out of memory? */
{
printf("Out of memory, aborting\n\n");
exit(1);
}
/* Do what ever your program does here */
free(x); /* Release the memeory */
return 0;
}
- Raw text -