TURBO PASCAL

Новости

Программы   

Turbo Pascal 

Игры

Документация   

Странности

FAQ

Ссылки

Форум

Гостевая книга

Рассылка

Благодарности

Об авторе

14: How can I create arrays that are larger than 64 kilobytes?

 A: Turbo Pascal does not directly support the so-called huge arrays
but you can get by this problem with a clever use of pointers as
presented in Kent Porter, "Handling Huge Arrays", Dr.Dobb's Journal,
March 1988. In this method you point to an element of a two
dimensional array using a^[row].col^[column]. The idea involves too
much code and explanation to be repeated here, so you'll have to see
the original reference. But I know from my own experience, that the
code works like magic. (The code is available from garbo.uwasa.fi
archives as ftp://garbo.uwasa.fi/pc/turbopas/ddj8803.zip). Kent
Porter, "Huge Arrays Revisited", Dr.Dobb's Journal, October 1988,
presents the extension of the idea to huge virtual arrays. (Virtual
arrays mean arrays that utilize disk space).
   Another possibility is using TurboPower Software's (the usual
disclaimer applies) commercial Turbo Professional (don't confuse
with Borland's Turbo Professional) package. It has facilities for
huge arrays, but they involve much more overhead than Kent Porter's
excellent method.
(* =================================================================
   My code below is based on a UseNet posting in the late
   comp.lang.pascal by Naji Mouawad nmouawad@watmath.waterloo.edu.
   Naji's idea was for a vector, my adaptation is for a
   two-dimensional matrix. The realization of the idea is simpler
   than the one presented by Kent Porter in Dr.Dobb's Journal, March
   1988. (Is something wrong, this is experimental.)
   ================================================================= *)
   {}
   const maxm = 150;
         maxn = 250;
   {}
   type BigVectorType = array [1..maxn] of real;
        BigMatrixType = array [1..maxm] of ^BigVectorType;
   {}
   var BigAPtr : BigMatrixType;
   {}
   (* Create the dynamic variables *)
   procedure MAKEBIG;
   var i          : word;
       heapNeeded : longint;
   begin
     heapNeeded := maxm * maxn * SizeOf(real) + maxm * 4 + 8196;
     if (MaxAvail <= heapNeeded) then
       begin writeln ('Out of memory'); halt; end;
     for i := 1 to maxm do New (BigAPtr[i]);
   end;  (* makebig *)
   {}
   (* Test that it works *)
   procedure TEST;
   var i, j : word;
   begin
     for i := 1 to maxm do
       for j := 1 to maxn do
         BigAPtr[i]^[j] := i * j;
     {}
     writeln (BigAPtr[5]^[7] : 0:0);
     writeln (BigAPtr[maxm]^[maxn] : 0:0);
   end;  (* test *)
   {}
   (* The main program *)
   begin
     writeln ('Big arrays test by Prof. Timo Salmi, Vaasa, Finland');
     writeln;
     MAKEBIG;
     TEST;
   end.
(For a better test of the heap than in MAKEBIG see Swan (1989), pp.
462-463.)

 Contents

На первую страницу

Rambler's Top100 Rambler's Top100
PROext: Top 1000

(с)Все права защищены

По всем интересующим вопросам прошу писать на электронный адрес

Hosted by uCoz