From 20770f388ee6e28b6d5ef91eb909e742d1725a00 Mon Sep 17 00:00:00 2001 From: Stephen Heumann Date: Sat, 3 Dec 2022 18:50:26 -0600 Subject: [PATCH] Move memory allocation code to a new function in MM. --- MM.pas | 28 ++++++++++++++++++++++++++++ Symbol.pas | 15 +-------------- 2 files changed, 29 insertions(+), 14 deletions(-) diff --git a/MM.pas b/MM.pas index d8ff341..d4e44fd 100644 --- a/MM.pas +++ b/MM.pas @@ -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 } diff --git a/Symbol.pas b/Symbol.pas index ffb8fba..ab69c14 100644 --- a/Symbol.pas +++ b/Symbol.pas @@ -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;