> How can code in the library test whether it is using cmem, so that it > can tell the caller that it's safe to call functions that > move strings > and objects around? It's obviously trivial to rely on a compile-time > conditional, but can this be done in a way that doesn't rely on this? >
Following little function detects whether the internal fp memory manager is used: function UsesFPCMemManager:boolean; var p:pointer; TotalAllocated:cardinal; const TESTSIZE=10000; begin TotalAllocated:=SysGetHeapStatus.TotalAllocated; getmem(p,TESTSIZE); Result:=SysGetHeapStatus.TotalAllocated-TotalAllocated>TESTSIZE; freemem(p); end; This is obviously not thread safe. Using Heaptrc doesn not affect the result. In case the internal memory manager is not used, it doesn't tell which one is used. Detecting that is much more difficult. Detecting that the c library is loaded is not enough because another unit could have included it. If there is debug info in the executable one could look up the addresses returned by GetMemoryManager. Ludo _______________________________________________ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal