Move memory allocation code to a new function in MM.

This commit is contained in:
Stephen Heumann 2022-12-03 18:50:26 -06:00
parent 7c0492cfa4
commit 20770f388e
2 changed files with 29 additions and 14 deletions

28
MM.pas
View File

@ -23,6 +23,7 @@
{ GCalloc - allocate & clear memory from the global pool }
{ GInit - initialize a global pool }
{ GMalloc - allocate memory from the global pool }
{ GLongMalloc - allocate global memory }
{ LInit - initialize a local pool }
{ LMalloc - allocate memory from the local pool }
{ Malloc - allocate memory }
@ -73,6 +74,15 @@ procedure GInit;
{ Initialize a global pool }
function GLongMalloc (bytes: longint): ptr;
{ Allocate a potentially large amount of global memory. }
{ }
{ Parameters: }
{ bytes - number of bytes to allocate }
{ ptr - points to the first byte of the allocated memory }
function GMalloc (bytes: integer): ptr;
{ Allocate memory from the global pool. }
@ -182,6 +192,24 @@ globalPtr := pointer(ord4(globalPtr) + bytes);
end; {GMalloc}
function GLongMalloc {bytes: longint): ptr};
{ Allocate a potentially large amount of global memory. }
{ }
{ Parameters: }
{ bytes - number of bytes to allocate }
{ ptr - points to the first byte of the allocated memory }
var
myhandle: handle; {for dereferencing the block}
begin {GLongMalloc}
myhandle := NewHandle(bytes, globalID, $C000, nil);
if ToolError <> 0 then TermError(5);
GLongMalloc := myhandle^;
end; {GLongMalloc}
procedure LInit;
{ Initialize a local pool }

View File

@ -306,16 +306,6 @@ type
var
staticNum: packed array[1..6] of char; {static variable number}
{---------------------------------------------------------------}
{GS memory manager}
{-----------------}
procedure DisposeHandle (theHandle: handle); tool ($02, $10);
function NewHandle (blockSize: longint; userID, memAttributes: integer;
memLocation: ptr): handle; tool($02, $09);
{- Imported from expression.pas --------------------------------}
procedure GenerateCode (tree: tokenPtr); extern;
@ -726,7 +716,6 @@ procedure DoGlobals;
var
buffPtr: ptr; {pointer to data buffer}
buffHandle: handle; {handle to data buffer}
count: integer; {# of duplicate records}
disp: longint; {disp into buffer (for output)}
endDisp: longint; {ending disp for current chunk}
@ -801,9 +790,7 @@ procedure DoGlobals;
begin {StaticInit}
{allocate buffer}
{(+3 for possible bitfield overhang)}
buffHandle := NewHandle(variable^.itype^.size+3, globalID, $8000, nil);
if ToolError <> 0 then TermError(5);
buffPtr := buffHandle^;
buffPtr := GLongMalloc(variable^.itype^.size+3);
relocs := nil; {evaluate initializers}
ip := variable^.iPtr;