[comp.lang.pascal] allocation an array >64K for large datasets.

Carl.Hu@f660.n250.z1.FidoNet.Org (Carl Hu) (04/30/91)

        Hello, I'm a C to Pascal programmer. To this point, I'd just like to

say how excellent Pascal is compared to C. Reliable, incredible compilation

speed, excellent coding efficiency. I love it. At least till now:

        Ran into a problem that would be easy in C. I desperately have to 
figure out a way to dimension an array greater than 64K. If that's 
impossible, then multiple 64K array's without using excess unit files. In 
C, there's memory models to handle that, in Pascal...I don't know. Somebody

care to enlighten me?

        Question 2: Saw a program in BYTE called PASCAL+. Looks like my 
dream programming language. Says it's faster in both Compilation and 
Execution than TP (!!). Also, has C extensions: memory models, full pointer

arithmetic. Does anybody know anything about this?  
 

nmouawad@watmath.waterloo.edu (Naji Mouawad) (05/02/91)

In article <673056705.1@egsgate.FidoNet.Org> Carl.Hu@f660.n250.z1.FidoNet.Org (Carl Hu) writes:
>        Hello, I'm a C to Pascal programmer. To this point, I'd just like to
>
>say how excellent Pascal is compared to C. Reliable, incredible compilation
>
>speed, excellent coding efficiency. I love it. At least till now:
>
>        Ran into a problem that would be easy in C. I desperately have to 
>figure out a way to dimension an array greater than 64K. If that's 
>impossible, then multiple 64K array's without using excess unit files. In 
>C, there's memory models to handle that, in Pascal...I don't know. Somebody
>
>care to enlighten me?

Although it is not possible to allocate more than 64k using getmem, you
can get around this by using a technic similar to the following one:

Suppose you need to allocate 4 arrays of 64k, you can declare:

Type 
  MyArray = Array[1..64k] of byte;
  PArray = ^MyArray;
  BigArray = Arrray[0..3] of ^MyArray;

Your arrays are instantiated at run time, via the `new' function.
How do you then access a byte ?

As you may have figured it out by now, you use the 'div' and 'mod' operators
to access a byte as follows:

Let us suppose you want to access byte number 82,456:
let index = 82,456 (note index is of type longint).
Let BigA be a variable of type BigArray.
You would do the following:

  BigA[index div 4]^[index mod 64k]

Index div 4 gives you the 'segment' the byte is in, while index mod
64k gives you the offset in that particular segment.

Note that if you implement this in assembler (TP 6.0), it would
be as efficient as in C.
 
>
>        Question 2: Saw a program in BYTE called PASCAL+. Looks like my 
>dream programming language. Says it's faster in both Compilation and 
>Execution than TP (!!). Also, has C extensions: memory models, full pointer
>
>arithmetic. Does anybody know anything about this?  
> 

which byte issue was this in ?

--Naji.
-- 
     -------------------------------------------------------------------
    | Naji Mouawad  |          nmouawad@watmath.waterloo.edu            |
    |  University   |---------------------------------------------------|
    | Of Waterloo   |   "The Stranger in us is our most familiar Self"  |