-
-
Notifications
You must be signed in to change notification settings - Fork 347
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added MSHeap.pas (https://github.com/RDP1974/DelphiMSHeap)
- Loading branch information
1 parent
1bccc50
commit 0374d8f
Showing
1 changed file
with
66 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
unit MSHeap; | ||
|
||
// default MM override using Windows Heap API | ||
// Roberto Della Pasqua www.dellapasqua.com | ||
// 10 sept 2022 added inline directive, zeromemory and freemem return value | ||
// 21 jun 2023 addition by Daniele Teti https://github.com/danieleteti/delphimvcframework | ||
|
||
{$O+} | ||
|
||
interface | ||
|
||
uses Windows; | ||
|
||
implementation | ||
|
||
var | ||
ProcessHeap: THandle; | ||
|
||
function SysGetMem(Size: NativeInt): Pointer; inline; | ||
begin | ||
Result := HeapAlloc(ProcessHeap, 0, Size); | ||
end; | ||
|
||
function SysFreeMem(P: Pointer): Integer; inline; //thanks Daniele Teti delphimvc | ||
begin | ||
Result := 0; | ||
if not HeapFree(ProcessHeap, 0, P) then Result := -1; | ||
end; | ||
|
||
function SysReallocMem(P: Pointer; Size: NativeInt): Pointer; inline; | ||
begin | ||
Result := HeapReAlloc(ProcessHeap, 0, P, Size); | ||
end; | ||
|
||
function SysAllocMem(Size: NativeInt): Pointer; inline; | ||
begin | ||
Result := HeapAlloc(ProcessHeap, 8, Size); // zeromemory in dwflags api call | ||
end; | ||
|
||
function SysRegisterExpectedMemoryLeak(P: Pointer): Boolean; | ||
begin | ||
Result := False; | ||
end; | ||
|
||
function SysUnregisterExpectedMemoryLeak(P: Pointer): Boolean; | ||
begin | ||
Result := False; | ||
end; | ||
|
||
const | ||
MemoryManager: TMemoryManagerEx = | ||
( | ||
GetMem: SysGetmem; | ||
FreeMem: SysFreeMem; | ||
ReallocMem: SysReAllocMem; | ||
AllocMem: SysAllocMem; | ||
RegisterExpectedMemoryLeak: SysRegisterExpectedMemoryLeak; | ||
UnregisterExpectedMemoryLeak: SysUnregisterExpectedMemoryLeak | ||
); | ||
|
||
initialization | ||
|
||
ProcessHeap := GetProcessHeap; | ||
SetMemoryManager(MemoryManager); | ||
|
||
end. |