[comp.sys.ibm.pc] structures >64K

tarvaine@tukki.jyu.fi (Tapani Tarvainen) (06/19/89)

In article <4410@crash.cts.com> jca@pnet01.cts.com (John C. Archambeau) writes:
>Just out of curiousity, what's the problem with > 64K structs?  Not that I've
>ever had a reason to use them.  Is it the addressing mode that structs use?
>I know > 64K arrays work in the compact, large, and huge models under TC 1.5.

If you ever need to use them, you'll find they only sort of work:

* A declaration like  int a[70000];  won't work in any memory model.
  All static data structures must be <64K in all models, and only in huge
  can their total size exceed it.  Automatic variables are allocated
  from the stack and must be <64K in huge model also.
  In small data models arrays should actually be <32K, by the way -
  you can declare int a[30000] in small model, but it won't work. 
  (This is because of the way pointer arithmetic is done.  Whether
  or not this is a bug was debated rather thoroughly in comp.lang.c
  some months ago.)
* Arrays >64K bytes can be created with farmalloc or farcalloc in all 
  large data models, like  int *a = farcalloc(50000,2),
  but more than 64K _elements_ can be accessed in huge model only --
  compact and large assume indices are unsigned ints.
* There is no way to create a struct consisting of (say) two
  70000K arrays.  The last element of a struct can be an array of
  unspecified size, however, and things like this will work:
        struct weird {
                int x;
                int y[];
        } *w = (struct weird *)farmalloc((1+y_length)*sizeof(int));
* Even in huge model, huge pointers must be explicitly declared as such,
  and index variables as long - size_t won't do, it is unsigned int in
  huge model also (this I consider a bug).
  Also note that calloc won't allocate a block >64Kbytes in any model, 
  you must use farcalloc.  (It won't complain, the program will just crash.)

To sum up, the problem is that if a program that runs just fine
in the small model runs out of memory and you need to increase the
size of some array beyond 64K, the program must probably be changed
in quite many places - you can't just switch to a large data model.

-- 
Tapani Tarvainen                 BitNet:    tarvainen@finjyu
Internet:  tarvainen@jylk.jyu.fi  -- OR --  tarvaine@tukki.jyu.fi