[fpc-devel] Question on IsMemoryManagerSet logic
Christo Crause
christo.crause at gmail.com
Sun Jan 23 13:15:39 CET 2022
Trying to detect at unit initialization if a memory manager has been
installed (xtensa-freertos) fails on FreeRTOS target. It appears that
IsMemoryManagerSet[1] always returns false for this target, even if a
custom memory manager has been installed. Looking at the implementation of
IsMemoryManagerSet shows that it will always return false if either
HAS_MEMORYMANAGER or FPC_NO_DEFAULT_MEMORYMANAGER is defined, if none of
these are defined, it will check if the getmem & freememare different to
the system defined routines.
For FreeRTOS both HAS_MEMORYMANAGER and FPC_NO_DEFAULT_MEMORYMANAGER are
defined, so it is impossible to detect if a custom memory manager has been
installed using IsMemoryManagerSet.
a) Am I using the correct approach to detect if a memory manager is
installed? I want to check if it is safe to use GetMem/FreeMem.
b) Is there a reason for the behaviour of IsMemoryManagerSet?
[1] From rtl/inc/heap.inc:
function IsMemoryManagerSet:Boolean;
begin
{$ifdef HAS_MEMORYMANAGER}
Result:=false;
{$else HAS_MEMORYMANAGER}
{$ifdef FPC_NO_DEFAULT_MEMORYMANAGER}
Result:=false;
{$else not FPC_NO_DEFAULT_MEMORYMANAGER}
IsMemoryManagerSet := (MemoryManager.GetMem<>@SysGetMem)
or (MemoryManager.FreeMem<>@SysFreeMem);
{$endif notFPC_NO_DEFAULT_MEMORYMANAGER}
{$endif HAS_MEMORYMANAGER}
end;
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20220123/3721793c/attachment.htm>
More information about the fpc-devel
mailing list