Ignore:
Timestamp:
Oct 30, 2010, 6:39:12 PM (14 years ago)
Author:
george
Message:
  • Added: Ability of TListObject to own items and be able to free them on deletion and list destruction.
Location:
Generics/TemplateGenerics/Demo
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • Generics/TemplateGenerics/Demo

    • Property svn:ignore
      •  

        old new  
        11lib
        22Demo.exe
         3heaptrclog.trc
         4Demo
  • Generics/TemplateGenerics/Demo/UMainForm.pas

    r76 r78  
    88  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
    99  ComCtrls, ListInteger, ListString, DictionaryString, QueueInteger, ListChar,
    10   ListPointer, DateUtils, ListVariant;
     10  ListPointer, DateUtils, ListVariant, Contnrs, ListObject;
    1111
    1212type
     
    1515
    1616  TMainForm = class(TForm)
     17    ButtonListObject: TButton;
    1718    ButtonBenchmark: TButton;
    1819    ButtonCharList: TButton;
     
    2627    procedure ButtonDictionaryStringClick(Sender: TObject);
    2728    procedure ButtonIntegerListClick(Sender: TObject);
     29    procedure ButtonListObjectClick(Sender: TObject);
    2830    procedure ButtonQueueIntegerClick(Sender: TObject);
    2931    procedure ButtonStringListClick(Sender: TObject);
     
    7173    MoveItems(3, 2, 3);
    7274    WriteLn('Implode: ' + Implode(',', IntToStr));
     75  finally
     76    Free;
     77  end;
     78end;
     79
     80function ObjectToStr(Obj: TObject): string;
     81begin
     82  Result := Obj.ClassName;
     83end;
     84
     85procedure TMainForm.ButtonListObjectClick(Sender: TObject);
     86var
     87  List: TListObject;
     88  I: Integer;
     89begin
     90  MemoOutput.Clear;
     91  WriteLn('TListObject test');
     92  List := TListObject.Create;
     93  with List do try
     94    AddArray([TObject.Create, TObject.Create, TObject.Create, TObject.Create]);
     95    WriteLn('Implode: ' + Implode(',', ObjectToStr));
     96    Clear;
     97    for I := 0 to 10 do Add(TObject.Create);
     98    WriteLn('Implode: ' + Implode(',', ObjectToStr));
     99    WriteLn('Count: ' + IntToStr(Count));
     100    WriteLn('Implode: ' + Implode(',', ObjectToStr));
     101    WriteLn('Reverse');
     102    Reverse;
     103    WriteLn('Implode: ' + Implode(',', ObjectToStr));
     104    MoveItems(3, 2, 3);
     105    WriteLn('Implode: ' + Implode(',', ObjectToStr));
    73106  finally
    74107    Free;
     
    207240    List.Clear;
    208241
     242    for I := 0 to 1000000 do
     243      List.Add(1);
     244    StartTime := Now;
     245    I := 0;
     246    repeat
     247      List.Exchange(300000, 700000);
     248      Inc(I);
     249    until (Now - StartTime) > OneSecond;
     250    WriteLn('Exchange: ' + IntToStr(I) + ' ops/sec');
     251    List.Clear;
     252
     253    for I := 0 to 1000000 do
     254      List.Add(1);
     255    StartTime := Now;
     256    I := 0;
     257    repeat
     258      List.IndexOf(Pointer(I mod List.Count));
     259      Inc(I);
     260    until (Now - StartTime) > OneSecond;
     261    WriteLn('IndexOf: ' + IntToStr(I) + ' ops/sec');
     262    List.Clear;
    209263  finally
    210264    List.Free;
     
    238292    WriteLn('Delete: ' + IntToStr(I) + ' ops/sec');
    239293
    240       for I := 0 to 1000000 do
    241       List2.Add(1);
     294    for I := 0 to 1000000 do
     295    List2.Add(1);
    242296    StartTime := Now;
    243297    I := 0;
     
    247301    until (Now - StartTime) > OneSecond;
    248302    WriteLn('Move: ' + IntToStr(I) + ' ops/sec');
     303
     304    for I := 0 to 1000000 do
     305    List2.Add(1);
     306    StartTime := Now;
     307    I := 0;
     308    repeat
     309      List2.Exchange(300000, 700000);
     310      Inc(I);
     311    until (Now - StartTime) > OneSecond;
     312    WriteLn('Exchange: ' + IntToStr(I) + ' ops/sec');
     313
     314    for I := 0 to 1000000 do
     315    List2.Add(1);
     316    StartTime := Now;
     317    I := 0;
     318    repeat
     319      List2.IndexOf(Pointer(I mod List.Count));
     320      Inc(I);
     321    until (Now - StartTime) > OneSecond;
     322    WriteLn('IndexOf: ' + IntToStr(I) + ' ops/sec');
    249323
    250324  finally
Note: See TracChangeset for help on using the changeset viewer.