[comp.lang.pascal] Dynamically allocating space to arrays > 64K

magid@sandstorm.Berkeley.EDU (Paul Magid) (01/10/91)

	First I would like to thank all the people who pointed me in the 
direction of DDJ article that answered my last question.  Below please find the 
code that I am now using, it is pretty much directly out of the article.  I
would now like to be able to allocate about 75% of the systems memory to the 
large data structure.  However,  I am at a loss for how to do it.  As it stands
the program either has enough memory to run or it does not, I would like to be
able to allocate a fixed proportion of available memory to it.  Thank you in 
advance for your help.

	Paul


================================================================================
const
	MAXROWS = 501; {7501}
	MAXCOLS = 82;


type
	colPtr = ^colArray;
	colArray = array [1..MAXCOLS] of char;
	colNode = record
	    cols : colPtr;
	End;
	rowPtr = ^rowArray;
	rowArray = array [1..MAXROWS] of colNode;

var
	Filecont:rowPtr;


Procedure create (var D     : rowPtr;
                  var error : Boolean);

  { Create huge array 'D' and pass back pointer to it }

Var   row : word;

Begin
  Error := false;
  If maxAvail > sizeof (rowArray) then     { if space available }
    GetMem (D, sizeof (rowArray))          { allocate row array }
  Else begin
    D := nil;
    Error := true;
  End;
  If D <> nil then
    For row := 1 to maxRows do begin        { allocate all rows }
      If not error then
        If maxAvail > sizeof (colArray) then         { if space }
          GetMem (D^ [row].cols, sizeof (colArray))  { alloc row }
        Else
          Error := true;
    End;
End;