Einzelnen Beitrag anzeigen

ventiseis

Registriert seit: 15. Jan 2009
Ort: 94032 Passau
53 Beiträge
 
Delphi 10.2 Tokyo Enterprise
 
#2

AW: TDictionary<K,V> und Kapazität

  Alt 4. Mär 2020, 21:17
Hier ein Testprogram zum Auslesen des Füllgrads für Delphi 10.2:

Delphi-Quellcode:
program Project7;

{$APPTYPE CONSOLE}

{$R *.res}

uses
  System.SysUtils, System.Generics.Collections, System.Rtti;

function GetGrowThreshold(AInstance: TObject): NativeUInt;
var
  LContext: TRttiContext;
  LType: TRttiType;
  LField: TRttiField;
begin
  LContext := TRttiContext.Create();
  LType := LContext.GetType(TDictionary<Integer, Integer>);
  LField := LType.GetField('FGrowThreshold');
  Result := LField.GetValue(AInstance).AsType<Integer>;
end;

var
  I: Integer;
  LDictionary: TDictionary<Integer, Integer>;

const

  C = 20;

begin
  LDictionary:=TDictionary<Integer, Integer>.Create(C);
  try

    for I := 1 to C do
    begin
      LDictionary.Add(i,i);
      WriteLn(IntToStr(i) + ': ' + GetGrowThreshold(LDictionary).ToString);
    end;
    ReadLn;
  finally
    FreeAndNil(LDictionary);
  end;
end.
Bastian
  Mit Zitat antworten Zitat