On Wed, July 4, 2012 11:32, Mark Morgan Lloyd wrote: > When building a shared library, I'm putting a (function that returns a) > magic number into both the library and the calling program. This returns > an integer, and allows the program and library to check their exposed > APIs without risk. > > 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?
First of all, you can easily check whether the default memory manager is used by calling IsMemoryManagerSet. Obviously, this doesn't tell whether the custom memory manager is cmem or something else (e.g. TraceManager from HeapTrace). However, you could possibly try to check the distance between the individual MemoryManager methods retrieved using GetMemoryManager - while that is not bulletproof by any means, it provides at least some indication. Finally, if there are certain major changes to features provided by individual memory managers (like some operation being safe or not), adding some TMemoryManager method allowing to provide this information may be the best solution for the future. Tomas _______________________________________________ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal