[comp.lang.pascal] Summary on arrays that are 300,300

SL960@cc.usu.edu (02/15/90)

This reply answers the question I asked about creating an array 
 > [300,300] to overcome the 64K block limit on the IBM 80286.


---------------------------------------------------------------
"PHYS169%canterbury.ac.nz@uunet.uu.net"  
"Mark Aitchison, U of Canty; Physics" writes:

> I am working on application which requires two dimensional arrays that are
> approximately 300 x 300 (var type real).  I am using version 5.5 of Turbo 
> Pascal.  
> 

As the structure exceeeds 64Kb you have to use the heap (or extended or
expanded memory). 

1. USING THE HEAP:
You can just squeeze in 300x300 6-byte reals (if your program and system 
overheads are low enough), but it is probably better to use 4-byte reals 
available with the 'single' type provided with the 8087 (or emulator).
You have to declare an array of 300 pointers to arrays of 300 reals...

Method: declare TYPE RealArray = array [0..300] of single;
                VAR  BigArray  : array [0..300] of ^RealArray;
        init    for i:=1 to 300 do new(BigArray[i]);
        access elements by (for example)...
                for i:=1 to 300 do
                    for j:=1 to 200 do
                        BigArray[i]^[j]:=i/j; {or whatever}

2. USING EMS:
This is messier, but may be essential if the total memory use exceeds 640Kb.
EMS memory systems partition memory into 16Kb chunks, so you can access any
four (typically) chunks out of (perhaps) 2Mb of RAM at a time. There is an
example of using EMS supplied with many versions of Turbo Pascal; you would
need to write a function that returns a pointer to a real, looking up what 
chunk of EMS is required and changing EMS pages first if required - that's a
lot of work of course, and there are complications (requiring remembering the
recent page assignments) to avoid problems when assigning a real in one chunk
(page) to another.  If you're desparate, I could help further - otherwise avoid
it!

3. USE A DIFFERENT STRUCTURE:
If the matrix is sparse, you can store pointers to only the elements used, e.g.
a matrix of nodes in a circuit or pipe network - you store a list of "links" or
pipe elements which typically requires *much* less storage than a simple matrix
containing lots of zero (wasted) entries.

4. USE A DIFFERENT COMPUTER:
Sadly, you are up against a limitation/nuisance with the PC architecture; use
either an 80386 chip (and a different compiler), or Pascal on a super-mini
(such as a VAX, DG MV/series, Sun, etc).

Mark Aitchison, Physics, University of Canterbury, New Zealand.
---------------------------------------------------------------

Everyone thanks for the help.
-- 
            ________________________________________________________
           /                                                        \  
          /                      Doug Stevenson                      \    
          |                                                          |
          \  sl960@cc.usu.edu : Internet         sl960@usu : Bitnet  /    
           \________________________________________________________/