anchor.diff:  end;
   
   function TThreadHeap.GetMedium(B16Count: NativeUInt; Align: NativeUInt{TMemoryAlign}): Pointer;
  +var
  +  Pool: PK64PoolMedium;
  +  Header: PHeaderMedium;
  +  Flags: NativeUInt;
  +begin
  +  if (Align = 0) then
  +  begin
  +    Pool := Self.QK64PoolMedium;
  +    if (Pool <> nil) then
  +    begin
  +      Header{Empty} := Pointer(Pool.Empties.First.Next);
  +      if (Header{Empty} <> Pointer(@Pool.Empties.Last)) then
  +      begin
  +        Flags{Size} := PHeaderMediumEmptyEx(Header{Empty}).Size;
  +        Inc(Header);
  +        Dec(NativeUInt(Header), Flags{Size});
  +        if (Flags{Size} and MASK_MEDIUM_SIZE_TEST = MASK_MEDIUM_SIZE_VALUE) and
  +          (NativeInt(Header) and MASK_K4_TEST <> 0) then
  +        begin
  +          Dec(Header);
  +          Flags := Flags{Size} shr 4;
  +          Inc(B16Count, 2);
  +          if (Flags = Header.Flags) and (Flags >= B16Count{ + 2}) then
  +          begin
  +            // Flags := Flags - B16Count - 1
  +            // (B16Count * 16)
  +            Dec(Flags, B16Count);
  +            Dec(B16Count, 2);
  +            Inc(Flags);
  +            B16Count := B16Count shl 4;
  +
  +            // make empty shorter
  +            // (Flags * 16)
  +            Inc(Header);
  +            Inc(NativeUInt(Header), B16Count);
  +            Header.PreviousSize := B16Count;
  +            Header.Flags := Flags{Empty B16Count};
  +            Flags := Flags shl 4;
  +            Inc(Header);
  +            Inc(NativeUInt(Header), Flags);
  +            Header.PreviousSize := Flags;
  +
  +            // result
  +            Dec(Header, 2);
  +            Dec(NativeUInt(Header), B16Count);
  +            B16Count := B16Count shr 4;
  +            Dec(NativeUInt(Header), Flags);
  +            Header.Flags := B16Count + {AllocatedFlags}MASK_MEDIUM_ALLOCATED;
  +            Result := Pointer(@PHeaderMediumList(Header)[0]);
  +            Exit;
  +          end;
  +          Dec(B16Count, 2);
  +        end;
  +      end;
  +
  +      Result := PK64PoolMedium(NativeInt(Header) and MASK_K64_CLEAR).ThreadHeap.PenaltyGetMedium(B16Count, 0);
  +    end else
  +    begin
  +      Result := Self.PenaltyGetMedium(B16Count, 0);
  +    end;
  +  end else
  +  begin
  +    Result := Self.PenaltyGetMedium(B16Count, Align);
  +  end;
  +end;
  +
  +function TThreadHeap.PenaltyGetMedium(B16Count: NativeUInt; Align: NativeUInt{TMemoryAlign}): Pointer;
   label
     done, ptr_invalid;
   var
  
positive.code: 
      function NewK64PoolMedium: PK64PoolMedium;
      function DisposeK64PoolMedium(PoolMedium: PK64PoolMedium): Integer;
    public
      // errors
      ErrorAddr: Pointer {address/nil};
  
negative.code: 
  function TThreadHeap.FreeMedium(P: Pointer): Integer;
  var
    Header: PHeaderMedium;
    Flags, EmptyFlags: NativeUInt;
    Pool: PK64PoolMedium;
  
    StoreHeader:  PHeaderMedium;
  begin
    // header flags
    Header := P;
    Dec(Header);
    Flags := Header.Flags;
  
    // if (Prev.Allocated) and (Next.Empty) then Grow(Next)
    EmptyFlags := Flags and MASK_MEDIUM_ALLOCATED_TEST;
    if (EmptyFlags = MASK_MEDIUM_ALLOCATED_VALUE) then
    begin
      EmptyFlags := PHeaderMedium(NativeUInt(Header) - Header.PreviousSize).Flags;
      EmptyFlags := EmptyFlags and MASK_MEDIUM_ALLOCATED_TEST;
      if (EmptyFlags = MASK_MEDIUM_ALLOCATED_VALUE) then
      begin
        StoreHeader := Header;
        Inc(Header);
        Flags := (Flags shl 4) and ($ffff shl 4);
        Inc(NativeUInt(Header), Flags);
        EmptyFlags := Header.Flags;
        if (EmptyFlags and MASK_MEDIUM_EMPTY_TEST = MASK_MEDIUM_EMPTY_VALUE) and
          (Header.PreviousSize = Flags) then
        begin
          // MediumEmpty.Size := MediumEmpty.Size + Size + 16
          EmptyFlags := EmptyFlags shl 4;
          Inc(Flags, 16);
          Inc(NativeUInt(Header{Empty}), EmptyFlags);
          Inc(Flags, EmptyFlags);
          if (Flags <> SizeOf(THeaderMediumList) - {Start}SizeOf(THeaderMedium)) then
          begin
            PHeaderMediumEmptyEx(Header{Empty}).Size := Flags;
  
            // new empty flags
            Dec(NativeUInt(Header), Flags);
            Flags := Flags shr 4;
            Header.Flags := Flags;
  
            if (StoreHeader <> Header) then
              GLOBAL_STORAGE[0] := 15;
  
            // result
            Result := FREEMEM_DONE;
            Exit;
          end else
          begin
            Pool := PK64PoolMedium(NativeInt(Header) and MASK_K64_CLEAR);
            Result := Pool.ThreadHeap.DisposeK64PoolMedium(Pool);
            Exit;
          end;
        end else
        begin
          Dec(Header);
          Dec(NativeUInt(Header), Flags);
        end;
      end;
    end;
  
    Inc(Header);
    Result := PK64PoolMedium(NativeInt(Header) and MASK_K64_CLEAR).ThreadHeap.PenaltyFreeMedium(Pointer(Header));
  end;
  
  function TThreadHeap.PenaltyFreeMedium(P: Pointer): Integer;
  var
    Information: NativeUInt;
    Pool: PK64PoolMedium;
    Empty, Left, Right: PHeaderMediumEmpty;
  