HELP NEEDED to declare very large global array

Peter Lim pnl at hpfinote.HP.COM
Thu Apr 12 05:34:44 AEST 1990


> 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 at 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 at hpsgwg.HP.COM     Snail-mail:  Hewlett Packard Singapore,    :
Tel:     (065)-279-2289                      (ICDS, ICS)                   |
Telnet:        520-2289                      1150 Depot Road,           __\@/__
  ... also at: pnl at hpfipnl.HP.COM            Singapore   0410.           SPLAT !



More information about the Comp.lang.c mailing list