Turbo C large character array

Doug Matlock doug at ozdaltx.UUCP
Tue Jul 31 02:17:53 AEST 1990


In article <1990Jul27.193520.4689 at ux1.cso.uiuc.edu>, gordon at osiris.cso.uiuc.edu (John Gordon) writes:
> 
> 	Hello.  I am having a problem, and I hope someone can help me.
> 
> 	I am trying to declare a char array that is rather large, and TCC
> won't accept it, it says it is too large to fit within available memory.
> 	By my calculations, this shoud be equal to 96K worth.  I am using
> the Huge model, which specifically says that arrays of more than 64K may be
> used.

Not quite.  The huge model "permits static data to total more than 64K. it must
still be less than 64K in *each* module". (pg 199 in the "new" manuals TC++).

If all you need is a very large array, and you always plan to access its
elements through a pair of indicies, I suggest you use the tack taken in
"Numerical Recipes in C".  A character "array" is defined as
char **x;

and allocated on the heap as

x = (char **)malloc(num_rows*sizeof(char));
for (i=0; i<num_rows, i++) x[i] = (char *)malloc(num_cols_in_row[i]*sizeof(char));

I have used this the great effect in many situations where I needed large
arrays.  It is also very effective when each row has a different number
of elements (i.e. I don't really have a true array, but double key access
to some collection of elements.)


-- 
Doug.

"If you want Peace, work for Justice."



More information about the Comp.lang.c mailing list