[comp.sys.atari.st] Big arrays in C

mrd@sun.mcs.clarkson.edu (Michael R. DeCorte) (04/21/88)

Does the new version of MWC support arrays > 64K.  I have an older
version (? 2.- ?) and it seems to get fairly upset at large arrays.
If not, do any of the compilers have large arrays or am I going to be
forced to hack the output of TeX-to-C?

wes@obie.UUCP (Barnacle Wes) (04/24/88)

In article <791@sun.mcs.clarkson.edu>, mrd@sun.mcs.clarkson.edu (Michael R. DeCorte) writes:
> Does the new version of MWC support arrays > 64K.  I have an older
> version (? 2.- ?) and it seems to get fairly upset at large arrays.
> If not, do any of the compilers have large arrays or am I going to be
> forced to hack the output of TeX-to-C?

Yes, MWC 3.0 will support arrays > 64K, and yes, MWC 2.1.7 already
supports arrays > 64K.  The same limitation applies to both: the array
MUST be either static or global (static data either way).

The reason for this is simple: the MWC compiler uses the `link'
instruction to allocate space for the auto variables from the stack.
On the 68000, the link instruction takes a signed 16-bit integer as the
stack offset to use.  Thus, the link instruction can allocate a maximum
of 32K of space for auto variables.  Thus the true array size
limitation is not really even 64K, it is 32K.

The compiler will complain about `strict: array size exceeds size_t',
but this is a `strict' message, which you can safely ignore.  It's
just telling you there is something you should check and make sure you
are doing what you really want to do.

Don't complain too much about making the arrays static, just think -
the MS-DOS world really can't get around their 64K limitation at all
without some truly WEIRD machinations.
-- 
    /\              -  "Against Stupidity,  -    {backbones}!
   /\/\  .    /\    -  The Gods Themselves  -  utah-cs!uplherc!
  /    \/ \/\/  \   -   Contend in Vain."   -   sp7040!obie!
 / U i n T e c h \  -       Schiller        -        wes

manis@faculty.cs.ubc.ca (Vince Manis) (04/27/88)

You actually don't want to have large arrays be 'auto'. Such an array 
swells up the stack, and if you should make a procedure with a large
auto array be recursive, you will suddenly get many copies of the
array. This is rarely what is wanted. 

There is another method of getting an array which works on just about 
every compiler, and doesn't require that the array size be known at compile 
time. I use this method in preference to static arrays:

   typedef ... element_type;

   element_type *array;

   array = calloc(n_elements, sizeof(element_type));
   /* In MWC, you'd probably use lcalloc to get more than 64K.
      malloc/lmalloc are faster, because they don't initialise
      the array to 0. */

   array[42] = ... ;    /* Pointers can also be subscripted, so
                           you can just use it like an array. */

   free(array);         /* When you no longer need it. */


Vincent Manis                    | manis@cs.ubc.ca
The Invisible City of Kitezh     | manis@cs.ubc.cdn
Department of Computer Science   | manis@ubc.csnet
University of British Columbia   | {ihnp4!alberta,uw-beaver,uunet}!
<<NOTE NEW ADDRESS>>             |      ubc-cs!manis