[fpc-pascal] How can a project determine if it's using cmem?

Tomas Hajny XHajT03 at hajny.biz
Wed Jul 4 14:27:57 CEST 2012


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





More information about the fpc-pascal mailing list