Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!tut.cis.ohio-state.edu!ucbvax!hplabs!hpfcso!hpfinote!pnl From: pnl@hpfinote.HP.COM (Peter Lim) Newsgroups: comp.lang.c Subject: Re: HELP NEEDED to declare very large global array Message-ID: <15080006@hpfinote.HP.COM> Date: 11 Apr 90 19:34:44 GMT References: <18817@oregon.uoregon.edu> Organization: Hewlett Packard CICD Lines: 52 > I am having problems declaring the following array as a global variable > using QuickC 2.0: > > #define MAX_CHANNELS 6 > #define MAX_SAMPLES 3000 > > float data[MAX_CHANNELS][MAX_SAMPLES]; > > void main(void) > { > /* use data[][] here */ > } > > In the interest of making this a good learning experience, please give me > both solutions (since my array is > 64K): > 1. Using a small or medium memory model. > 2. Using a huge memory model. > > Thank you very much for any help. > > Michel Biedermann michelbi@oregon.uoregon.edu > U. of Oregon > ---------- You sure have a problem here. As far as I can remember, nothing in MS-DOS (short of using DOS extender) allow you to declare a 'simple' array > 64K size (PERIOD). You need to play with pointers. In your case, why don't just declare an array of 6 pointers, each is then used to index 3000 samples. Like: float (*dptr)[MAX_CHANNELS]; for (i=0; i < MAX_CHANNELS; i++) (*dptr)[i] = (float *) malloc ((unsigned) (MAX_SAMPLES * sizeof (float))); then proceed to use (*(dptr+j))[i] ..... in place of data[i][j]. /* NOTE: The above program fragments are dreamt up in the nick of time and I'm sure they will not work the first time. I can never quite remember the order of parenthesis; you need to play with them yourself. But I think the general idea is there. */ Regards, ## Life is fast enough as it is ........ Peter Lim. ## .... DON'T PUSH IT !! >>>-------, ########################################### : E-mail: plim@hpsgwg.HP.COM Snail-mail: Hewlett Packard Singapore, : Tel: (065)-279-2289 (ICDS, ICS) | Telnet: 520-2289 1150 Depot Road, __\@/__ ... also at: pnl@hpfipnl.HP.COM Singapore 0410. SPLAT !