Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2022-01

Question on IsMemoryManagerSet logic

1 message · 1 person ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Christo Crause

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 := ()
    or ();
{$endif notFPC_NO_DEFAULT_MEMORYMANAGER}
{$endif HAS_MEMORYMANAGER}
end;

Reply by email