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 functions GetMemoryManager and SetMemoryManager that help with that:

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); overload; ...

Get Mastering Delphi Programming: A Complete Reference Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.