Einzelnen Beitrag anzeigen

bernhard_LA

Registriert seit: 8. Jun 2009
Ort: Bayern
1.138 Beiträge
 
Delphi 11 Alexandria
 
#11

AW: Generic class <T> , wie füge ich konkrete Daten ein ?

  Alt 11. Jan 2024, 00:56
Generic List TList<CLass> vs. TList<Records> bei meinen Versuchen liegt TList<Rec> deutlich vor der Class Variante , in Bezug auf Speed und Speicherverbrauch,
sehe ich hier was falsch?




Delphi-Quellcode:
type

  /// <summary>
  /// here it is just a simple pixel but can be more in future
  /// </summary>
  TClusterData3 = class
    DrawingColor: TColor;
    x, y: Integer;
    chrlabel : char;
    // ...
    // ..
    // .
  end;


  TClusterData3REC = record
    DrawingColor: TColor;
    x, y: Integer;
    chrlabel : char;
    // ...
    // ..
    // .
  end;



  /// <summary>
  /// a bit different pixeldefinition
  /// </summary>
  TClusterData2 = class
    BWColor: Byte;
    x, y: Integer;
    // tbd.
    // ...
    // ..
    // .
  end;

  TClusterData = class
    DrawingColor: TColor;
    x, y: Integer;
  end;

  /// <summary>
  /// here it can be just a simple pixel, in general we store the complete morginal data inside this list
  /// </summary>
  TRawData<T> = class(TList<T>)
  end;






procedure TForm1.CornerButton_list_classClick(Sender: TObject);
var
      rawdata_class : TRawData<TClusterData3>;
      i : Integer;
      newclass : TClusterData3;

begin

     StatusbarLabel.Text := ' Create Elements';

     AProfiler.Start;

     rawdata_class:=TRawData<TClusterData3>.Create;

     for I := 0 to (16000*16000) do
       begin
          newclass :=TClusterData3.Create;

          newclass.x := random(1000);
          newclass.y := random(1000);
          newclass.DrawingColor := 20000 ;

          rawdata_class.Add(newclass);
       end;

      AProfiler.Stop;

      StatusbarLabel.Text := 'DONE CLASS: ' + AProfiler.GetElapsedTime(total_time) ;

       rawdata_class.Free;
end;

procedure TForm1.CornerButton_list_recClick(Sender: TObject);
var rawdata_rec : TRawData<TClusterData3REC>;
      i : Integer;
      newrec : TClusterData3REC;

begin

     StatusbarLabel.Text := ' Create Elements';

     AProfiler.Start;

     rawdata_rec:=TRawData<TClusterData3REC>.Create;

     for I := 0 to (16000*16000) do
       begin
          newrec.x := random(1000);
          newrec.y := random(1000);
          newrec.DrawingColor := 20000 ;

          rawdata_rec.Add(newrec);
       end;

      AProfiler.Stop;

      StatusbarLabel.Text := 'DONE REC: ' + AProfiler.GetElapsedTime(total_time) ;

      rawdata_rec.Free;
end;
Miniaturansicht angehängter Grafiken
class_vs_record.png  
  Mit Zitat antworten Zitat