Replacing the default memory manager
While writing a new memory manager is a hard job, installing it in Delphi—once it is completed—is very simple. The System unit implements GetMemoryManager
and SetMemoryManager
functions that help with that, as illustrated here:
type TMemoryManagerEx = record {The basic (required) memory manager functionality} GetMem: function(Size: NativeInt): Pointer; FreeMem: function(P: Pointer): Integer; ReallocMem: function(P: Pointer; Size: NativeInt): Pointer; {Extended (optional) functionality.} AllocMem: function(Size: NativeInt): Pointer; RegisterExpectedMemoryLeak: function(P: Pointer): Boolean; UnregisterExpectedMemoryLeak: function(P: Pointer): Boolean; end; procedure GetMemoryManager( var MemMgrEx: TMemoryManagerEx...