FastMM is a fast replacement memory manager for Embarcadero Delphi applications that scales well across multiple threads and CPU cores, is not prone to memory fragmentation, and supports shared memory without the use of external .DLL files.
{Insert the block in the first available arena.}
while True do
begin
LPLargeBlockManager := @LargeBlockManagers[0];
for LArenaIndex := 0 to CFastMM_LargeBlockArenaCount - 1 do
begin
if (LPLargeBlockManager.LargeBlockManagerLocked = 0)
and (AtomicExchange(LPLargeBlockManager.LargeBlockManagerLocked, 1) = 0) then
begin
PLargeBlockHeader(Result).LargeBlockManager := LPLargeBlockManager;
{Insert the large block into the linked list of large blocks}
LOldFirstLargeBlock := LPLargeBlockManager.FirstLargeBlockHeader;
PLargeBlockHeader(Result).PreviousLargeBlockHeader := Pointer(LPLargeBlockManager);
LPLargeBlockManager.FirstLargeBlockHeader := Result;
PLargeBlockHeader(Result).NextLargeBlockHeader := LOldFirstLargeBlock;
LOldFirstLargeBlock.PreviousLargeBlockHeader := Result;
LPLargeBlockManager.LargeBlockManagerLocked := 0;
{Add the size of the header}
Inc(PByte(Result), CLargeBlockHeaderSize);
Exit;
end;
{Try the next arena.}
Inc(LPLargeBlockManager);
end;
end;
{All large block managers are locked: Back off and try again.}
LogLargeBlockThreadContentionAndYieldToOtherThread;
The call to LogLargeBlockThreadContentionAndYieldToOtherThread must be inside a loop, otherwise it will never reach it.
In the function FastMM_GetMem_GetLargeBlock
The call to LogLargeBlockThreadContentionAndYieldToOtherThread must be inside a loop, otherwise it will never reach it.