From: i96csm AT river DOT tay DOT ac DOT uk Newsgroups: comp.os.msdos.djgpp Subject: Re: Large arrays eating disk space Message-ID: <1997Oct15.115139.1@river.tay.ac.uk> Date: 15 Oct 97 11:51:39 +0100 References: Organization: University of Abertay Dundee Lines: 47 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk In article , "J. Hormuzdiar" 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; }