Notes to myself:
I bumped into some legacy code with a windows process and DLLs both using ShareMem
(now System.ShareMem
) so that strings could be shared between the instances.
There were lots of memory leaks, so migrating to FastMM was important.
I followed these steps to get rid of ShareMem:
- Put
FastMM4
at the top of the uses lists for both the application and DLL projects - Remove
ShareMem
from these uses lists (in fact from any unit used) - Follow the FAQ ensuring these defines are globally in all projects involved:
ShareMM;ShareMMIfLibrary;AttemptToUseSharedMM
in each project file or the below in a fork of the FastMM4 repository fileFastMM4Options.inc
{$define ShareMM} {$define ShareMMIfLibrary} {$define AttemptToUseSharedMM}
- Q: How do I get my DLL and main application to share FastMM so I can safely pass long strings and dynamic arrays between them?
- A: The easiest way is to define
ShareMM
,ShareMMIfLibrary
andAttemptToUseSharedMM
inFastMM4.pas
and addFastMM4.pas
to the top of the uses section of the.dpr
for both the main application and the DLL.
- Resolve any error like
[dcc32 Error] E2201 Need imported data reference ($G) to access 'IsMultiThread' from unit 'FastMM4'
: in projects that depend on run-time packages. Luckily, how to do that is in the FAQ too:- Q: I get the following error when I try to use FastMM with an application compiled to use packages: “[Error] Need imported data reference (
$G
) to access ‘IsMultiThread
‘ from unit ‘FastMM4
‘”. How do I get it to work? - A: Enable the “
UseRuntimePackages
” option inFastMM4Options.inc
.
- Q: I get the following error when I try to use FastMM with an application compiled to use packages: “[Error] Need imported data reference (
Related:
- [WayBack] Delphi 2007 – Writing Dynamically Loaded Libraries: Shared-Memory Manager (Win32 Only)
- [WayBack] GitHub – pleriche/FastMM4: A memory manager for Delphi and C++ Builder with powerful debugging facilities
- [WayBack] FastMM4/FastMM4Options.inc at master · pleriche/FastMM4 · GitHub
- [WayBack] FastMM4/FastMM4_FAQ.txt at master · pleriche/FastMM4 · GitHub: share FastMM so I can safely pass long strings and dynamic arrays
- [WayBack] FastMM4/FastMM4_FAQ.txt at master · pleriche/FastMM4 · GitHub: “[Error] Need imported data reference ($G) to access ‘IsMultiThread’ from unit ‘FastMM4′”
- [WayBack] delphi – FastMM and Dynamically loaded DLLs – Stack Overflow
- Confusing Delphi message: [DCC Error] E2201 Need imported data reference ($G) to access ‘VarCopyProc’ from unit ‘XXX’
Note:
- I did not use
SimpleShareMem
(nowSystem.SimpleShareMem
) as the source of it did not tell me anything about FastMM4 compatibility. - A long time ago, FastMM changed the
EnableBackwardCompatibleMMSharing
from the oldEnableSharingWithDefaultMM
conditional define.
–jeroen