decalring large arrays

Martin Peter Howell s874330 at minyos.xx.rmit.oz.au
Thu Jun 20 02:17:02 AEST 1991


tomr at maccs.dcss.mcmaster.ca (Rickey Thomas Tom) writes:

>I have a simple question. I sort some data. The easiest way to do this is to 
>decalre a large array to sotre this data and then sort the array. However,
>it apopears that in a DOS environment, I am only allowed an array up to 64 K in size. Is there a way to declare larger arrays than this for sort. Is there another way that I could store a large quantity of data for sorting.

>Any comments would be appreciated. Thanks in advance.

A good way to do this is to define a series of small arrays and then use a
macro to index them transparently

#define SIZE        30000
#define Index(i)    Arrays[i/SIZE][i % SIZE]

int Array1[SIZE];
int Array2[SIZE];
int Array3[SIZE];

int *Arrays[3] = { Array1, Array2, Array3 };

This simulates an array of 90000 ints that can be indexed in the (almost)
normal way eg.,

for (i = 0; i < 90000L; ++i)
    Index(i) = i;

In practice you would probably want to malloc() each of the small arrays
and change the Index macro to do bit fiddling to speed it up.

---
s874330 at minyos.xx.rmit.oz.au               This sentance has threee errors.



More information about the Comp.lang.c mailing list