Skip to content
31 changes: 31 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
[core]
autocrlf=true

# Set the default behavior, in case people don't have core.autocrlf set.

# Explicitly declare text files you want to always be normalized and converted
# to native line endings on checkout.
*.c text
*.h text

# Declare files that will always have LF line endings on checkout.
*.md text eol=lf

# Declare files that will always have CRLF line endings on checkout.
*.txt text eol=crlf
*.reg text eol=crlf
*.sln text eol=crlf
*.dpr text eol=crlf
*.pas text eol=crlf
*.dfm text eol=crlf
*.inc text eol=crlf
*.lua text eol=crlf
.gitmodules text eol=crlf
.gitattribute text eol=crlf
.gitignore text eol=crlf
*.cmd text eol=crlf

# Denote all files that are truly binary and should not be modified.
*.png binary
*.jpg binary
*.bmp binary
286 changes: 143 additions & 143 deletions BorlndMM DLL/BorlndMM.dpr
Original file line number Diff line number Diff line change
@@ -1,143 +1,143 @@
{
Replacement BorlndMM.DLL using FastMM5
Description:
A replacement borlndmm.dll using FastMM5 instead of the RTL memory manager. This DLL may be used instead of the
default DLL together with your own applications, exposing the benefits of using FastMM5 to them.
Usage:
1) Compile this DLL
2) Ship it with your applications that currently use the borlndmm.dll file that ships with Delphi.
}
{$IMAGEBASE $00D20000}
// JCL_DEBUG_EXPERT_INSERTJDBG ON
library BorlndMM;
uses
FastMM5 in '..\FastMM5.pas',
{System.SysUtils is needed for exception handling.}
System.SysUtils;
{$R *.RES}
function GetAllocMemCount: Integer;
begin
Result := 0;
end;
function GetAllocMemSize: Integer;
begin
Result := 0;
end;
procedure DumpBlocks;
begin
{Do nothing}
end;
function HeapRelease: Integer;
begin
{Do nothing}
Result := 2;
end;
function HeapAddRef: Integer;
begin
{Do nothing}
Result := 2;
end;
function FastMM_GetOutputDebugStringEvents: TFastMM_MemoryManagerEventTypeSet;
begin
Result := FastMM_OutputDebugStringEvents;
end;
procedure FastMM_SetOutputDebugStringEvents(AEventTypes: TFastMM_MemoryManagerEventTypeSet);
begin
FastMM_OutputDebugStringEvents := AEventTypes;
end;
function FastMM_GetLogToFileEvents: TFastMM_MemoryManagerEventTypeSet;
begin
Result := FastMM_LogToFileEvents;
end;
procedure FastMM_SetLogToFileEvents(AEventTypes: TFastMM_MemoryManagerEventTypeSet);
begin
FastMM_LogToFileEvents := AEventTypes;
end;
function FastMM_GetMessageBoxEvents: TFastMM_MemoryManagerEventTypeSet;
begin
Result := FastMM_MessageBoxEvents;
end;
procedure FastMM_SetMessageBoxEvents(AEventTypes: TFastMM_MemoryManagerEventTypeSet);
begin
FastMM_MessageBoxEvents := AEventTypes;
end;
{$ifdef DEBUG}
{The debug support library must be statically linked in order to prevent it from being unloaded before the leak check
can be performed.}
function LogStackTrace(AReturnAddresses: PNativeUInt; AMaxDepth: Cardinal; ABuffer: PAnsiChar): PAnsiChar;
external {$if SizeOf(Pointer) = 4}'FastMM_FullDebugMode.dll'{$else}'FastMM_FullDebugMode64.dll'{$endif}
name 'LogStackTrace';
{$endif}
exports
GetAllocMemSize name 'GetAllocMemSize',
GetAllocMemCount name 'GetAllocMemCount',
FastMM_GetHeapStatus name 'GetHeapStatus',
DumpBlocks name 'DumpBlocks',
System.ReallocMemory name 'ReallocMemory',
System.FreeMemory name 'FreeMemory',
System.GetMemory name 'GetMemory',
{$ifdef DEBUG}
FastMM_DebugReallocMem name '@Borlndmm@SysReallocMem$qqrpvi',
FastMM_DebugFreeMem name '@Borlndmm@SysFreeMem$qqrpv',
FastMM_DebugGetMem name '@Borlndmm@SysGetMem$qqri',
FastMM_DebugAllocMem name '@Borlndmm@SysAllocMem$qqri',
{$else}
FastMM_ReallocMem name '@Borlndmm@SysReallocMem$qqrpvi',
FastMM_FreeMem name '@Borlndmm@SysFreeMem$qqrpv',
FastMM_GetMem name '@Borlndmm@SysGetMem$qqri',
FastMM_AllocMem name '@Borlndmm@SysAllocMem$qqri',
{$endif}
FastMM_RegisterExpectedMemoryLeak(ALeakedPointer: Pointer) name '@Borlndmm@SysRegisterExpectedMemoryLeak$qqrpi',
FastMM_UnregisterExpectedMemoryLeak(ALeakedPointer: Pointer) name '@Borlndmm@SysUnregisterExpectedMemoryLeak$qqrpi',
HeapRelease name '@Borlndmm@HeapRelease$qqrv',
HeapAddRef name '@Borlndmm@HeapAddRef$qqrv',
{Export additional calls in order to make FastMM specific functionality available to the application and/or library.}
FastMM_WalkBlocks,
FastMM_ScanDebugBlocksForCorruption,
FastMM_GetUsageSummary,
FastMM_LogStateToFile,
FastMM_EnterMinimumAddressAlignment,
FastMM_ExitMinimumAddressAlignment,
FastMM_GetCurrentMinimumAddressAlignment,
FastMM_SetDefaultEventLogFilename,
FastMM_SetEventLogFilename,
FastMM_GetEventLogFilename,
FastMM_DeleteEventLogFile,
FastMM_GetOutputDebugStringEvents,
FastMM_SetOutputDebugStringEvents,
FastMM_GetLogToFileEvents,
FastMM_SetLogToFileEvents,
FastMM_GetMessageBoxEvents,
FastMM_SetMessageBoxEvents;
begin
{$ifdef DEBUG}
{Touch LogStackTrace in order to prevent the linker from eliminating the static link to the debug support library.}
if @LogStackTrace <> nil then
begin
FastMM_EnterDebugMode;
FastMM_MessageBoxEvents := FastMM_MessageBoxEvents + [mmetUnexpectedMemoryLeakDetail, mmetUnexpectedMemoryLeakSummary];
end;
{$endif}
end.
{

Replacement BorlndMM.DLL using FastMM5

Description:
A replacement borlndmm.dll using FastMM5 instead of the RTL memory manager. This DLL may be used instead of the
default DLL together with your own applications, exposing the benefits of using FastMM5 to them.

Usage:
1) Compile this DLL
2) Ship it with your applications that currently use the borlndmm.dll file that ships with Delphi.

}

{$IMAGEBASE $00D20000}

// JCL_DEBUG_EXPERT_INSERTJDBG ON
library BorlndMM;

uses
FastMM5 in '..\FastMM5.pas',
{System.SysUtils is needed for exception handling.}
System.SysUtils;

{$R *.RES}

function GetAllocMemCount: Integer;
begin
Result := 0;
end;

function GetAllocMemSize: Integer;
begin
Result := 0;
end;

procedure DumpBlocks;
begin
{Do nothing}
end;

function HeapRelease: Integer;
begin
{Do nothing}
Result := 2;
end;

function HeapAddRef: Integer;
begin
{Do nothing}
Result := 2;
end;

function FastMM_GetOutputDebugStringEvents: TFastMM_MemoryManagerEventTypeSet;
begin
Result := FastMM_OutputDebugStringEvents;
end;

procedure FastMM_SetOutputDebugStringEvents(AEventTypes: TFastMM_MemoryManagerEventTypeSet);
begin
FastMM_OutputDebugStringEvents := AEventTypes;
end;

function FastMM_GetLogToFileEvents: TFastMM_MemoryManagerEventTypeSet;
begin
Result := FastMM_LogToFileEvents;
end;

procedure FastMM_SetLogToFileEvents(AEventTypes: TFastMM_MemoryManagerEventTypeSet);
begin
FastMM_LogToFileEvents := AEventTypes;
end;

function FastMM_GetMessageBoxEvents: TFastMM_MemoryManagerEventTypeSet;
begin
Result := FastMM_MessageBoxEvents;
end;

procedure FastMM_SetMessageBoxEvents(AEventTypes: TFastMM_MemoryManagerEventTypeSet);
begin
FastMM_MessageBoxEvents := AEventTypes;
end;

{$ifdef DEBUG}
{The debug support library must be statically linked in order to prevent it from being unloaded before the leak check
can be performed.}
function LogStackTrace(AReturnAddresses: PNativeUInt; AMaxDepth: Cardinal; ABuffer: PAnsiChar): PAnsiChar;
external {$if SizeOf(Pointer) = 4}'FastMM_FullDebugMode.dll'{$else}'FastMM_FullDebugMode64.dll'{$endif}
name 'LogStackTrace';
{$endif}

exports
GetAllocMemSize name 'GetAllocMemSize',
GetAllocMemCount name 'GetAllocMemCount',
FastMM_GetHeapStatus name 'GetHeapStatus',
DumpBlocks name 'DumpBlocks',
System.ReallocMemory name 'ReallocMemory',
System.FreeMemory name 'FreeMemory',
System.GetMemory name 'GetMemory',
{$ifdef DEBUG}
FastMM_DebugReallocMem name '@Borlndmm@SysReallocMem$qqrpvi',
FastMM_DebugFreeMem name '@Borlndmm@SysFreeMem$qqrpv',
FastMM_DebugGetMem name '@Borlndmm@SysGetMem$qqri',
FastMM_DebugAllocMem name '@Borlndmm@SysAllocMem$qqri',
{$else}
FastMM_ReallocMem name '@Borlndmm@SysReallocMem$qqrpvi',
FastMM_FreeMem name '@Borlndmm@SysFreeMem$qqrpv',
FastMM_GetMem name '@Borlndmm@SysGetMem$qqri',
FastMM_AllocMem name '@Borlndmm@SysAllocMem$qqri',
{$endif}
FastMM_RegisterExpectedMemoryLeak(ALeakedPointer: Pointer) name '@Borlndmm@SysRegisterExpectedMemoryLeak$qqrpi',
FastMM_UnregisterExpectedMemoryLeak(ALeakedPointer: Pointer) name '@Borlndmm@SysUnregisterExpectedMemoryLeak$qqrpi',
HeapRelease name '@Borlndmm@HeapRelease$qqrv',
HeapAddRef name '@Borlndmm@HeapAddRef$qqrv',
{Export additional calls in order to make FastMM specific functionality available to the application and/or library.}
FastMM_WalkBlocks,
FastMM_ScanDebugBlocksForCorruption,
FastMM_GetUsageSummary,
FastMM_LogStateToFile,
FastMM_EnterMinimumAddressAlignment,
FastMM_ExitMinimumAddressAlignment,
FastMM_GetCurrentMinimumAddressAlignment,
FastMM_SetDefaultEventLogFilename,
FastMM_SetEventLogFilename,
FastMM_GetEventLogFilename,
FastMM_DeleteEventLogFile,
FastMM_GetOutputDebugStringEvents,
FastMM_SetOutputDebugStringEvents,
FastMM_GetLogToFileEvents,
FastMM_SetLogToFileEvents,
FastMM_GetMessageBoxEvents,
FastMM_SetMessageBoxEvents;

begin
{$ifdef DEBUG}
{Touch LogStackTrace in order to prevent the linker from eliminating the static link to the debug support library.}
if @LogStackTrace <> nil then
begin
FastMM_EnterDebugMode;
FastMM_MessageBoxEvents := FastMM_MessageBoxEvents + [mmetUnexpectedMemoryLeakDetail, mmetUnexpectedMemoryLeakSummary];
end;
{$endif}
end.
70 changes: 37 additions & 33 deletions Demos/Memory Manager Sharing/Delay loaded DLL/FastMMInitSharing.pas
Original file line number Diff line number Diff line change
@@ -1,33 +1,37 @@
{Important note: This has to be the first unit in the DPR, because memory managers cannot be switched once memory has
been allocated, and the initialization sections of other units are likely to allocate memory.}

unit FastMMInitSharing;

interface

uses
FastMM5;

implementation

initialization
{First try to share this memory manager. This will fail if another module is already sharing its memory manager. In
case of the latter, try to use the memory manager shared by the other module.}
if FastMM_ShareMemoryManager then
begin
{Try to load the debug support library (FastMM_FullDebugMode.dll, or FastMM_FullDebugMode64.dll under 64-bit). If
it is available, then enter debug mode.}
if FastMM_LoadDebugSupportLibrary then
begin
FastMM_EnterDebugMode;
{In debug mode, also show the stack traces for memory leaks.}
FastMM_MessageBoxEvents := FastMM_MessageBoxEvents + [mmetUnexpectedMemoryLeakDetail];
end;
end
else
begin
{Another module is already sharing its memory manager, so try to use that.}
FastMM_AttemptToUseSharedMemoryManager;
end;

end.
{Important note: This has to be the first unit in the DPR, because memory managers cannot be switched once memory has
been allocated, and the initialization sections of other units are likely to allocate memory.}

unit FastMMInitSharing;


interface


uses
FastMM5;


implementation

initialization
{First try to share this memory manager. This will fail if another module is already sharing its memory manager. In
case of the latter, try to use the memory manager shared by the other module.}
if FastMM_ShareMemoryManager then
begin
{Try to load the debug support library (FastMM_FullDebugMode.dll, or FastMM_FullDebugMode64.dll under 64-bit). If
it is available, then enter debug mode.}
if FastMM_LoadDebugSupportLibrary then
begin
FastMM_EnterDebugMode;
{In debug mode, also show the stack traces for memory leaks.}
FastMM_MessageBoxEvents := FastMM_MessageBoxEvents + [mmetUnexpectedMemoryLeakDetail];
end;
end
else
begin
{Another module is already sharing its memory manager, so try to use that.}
FastMM_AttemptToUseSharedMemoryManager;
end;


end.
Loading