Reputation: 16620
This question is a follow up of this question.
How can I achieve that my application and my runtime package use the same memory manager? I thought that this was the case by default but since I get strange access violations and invalid pointer exceptions, I inserted calls to GetMemoryManagerState
just before entry to the runtime package and in the runtime package and the returned state seems to indicate that the package and the application use separate memory managers.
Before calling a method in the runtime package, there are 61 allocated medium blocks and after the call (at the beginning of the called method inside the package) there are 0 allocated medium blocks.
Do you happen to have an explanation for that? What do I have to do to make package and application share the memory manager? Any more complicated issues when using FastMM?
EDIT BTW, is there a better way to check if the same memory manager is used than comparing memory manager state? TMemoryManager
turns out to be a record, so I can't compare adresses.
Upvotes: 2
Views: 846
Reputation: 26371
A package uses the same RTL state as the main program. That is part of the definition of package.
Memorymanager inclusive.
Btw, my notes about packages are here: http://wiki.freepascal.org/packages
Currently FPC is still quite far away from this (mainly due to the need to implement this on umpteen OSes and architectures through an external linker). Also due to the larger number of FPC versions in roulation, I suspect it will be less useful than many people think (I don't expect Lazarus components to be ever distributed in something as binary only FPC equivalent of BPLs/.dcp combos)
Upvotes: 4
Reputation: 16620
Thanks to ldsandon and Rob Kennedy I figured out that it is necessary to use runtime packages (at least for the RTL) in order for the application and the package to share memory managers.
Enabling "Use runtime packages" and adding "rtl" to the package list solved the problem. Thanks to you all for your help.
Upvotes: 1