ORCA-C/MM.pas

1 line
8.6 KiB
ObjectPascal
Raw Normal View History

{$optimize 7} {---------------------------------------------------------------} { } { Memory Manager } { } { This memory manager provides a stack-based memory allocation } { and deallocation mechanism to allow compact symbol tables } { that can be disposed of with a single call after a function } { has been compiled. Two separate stacks, or pools, are } { available. The local pool is typically disposed of when } { the compilation of a function is complete. It is used for } { local memory allocations such as local strings and symbols. } { The global pool is used for global values like macro } { definitions and global symbols. } { } { External Variables: } { localID - userID for the local pool } { globalID - userID for the global pool } { } { External Subroutines: } { DisposeLocalPool - dump the local memory pool } { Calloc - clear and allocate memory } { GCalloc - allocate & clear memory from the global pool } { GInit - initialize a global pool } { GMalloc - allocate memory from the global pool } { LInit - initialize a local pool } { LMalloc - allocate memory from the local pool } { Malloc - allocate memory } { MMQuit - Dispose of memory allocated with private user } { IDs } { } {---------------------------------------------------------------} unit MM; {$LibPrefix '0/obj/'} interface uses CCommon; var localID,globalID: integer; {user ID's for the local & global pools} {---------------------------------------------------------------} function Calloc (bytes: integer): ptr; extern; { Allocate memory from a pool and set it to 0. } { } { Parameters: } { bytes - number of bytes to allocate } { ptr - points to the first byte of the allocated memory } { } { Globals: } { useGlobalPool - should the memory come from the global } { (or local) pool } function GCalloc (bytes: integer): ptr; extern; { Allocate and clear memory from the global pool. } { } { Parameters: } { bytes - number of bytes to allocate } { ptr - points to the first byte of the allocated memory } procedure GInit; { Initialize a global pool } function GMalloc (bytes: integer): ptr; { Allocate memory from the global pool. } { } { Parameters: } { bytes - number of bytes to allocate } { ptr - points to the first byte of the allocated memory } procedure LInit; { Initialize a local pool } function LMalloc (bytes: integer): ptr; { Allocate memory from the local pool. } { } { Parameters: } { bytes