DELPHI性能优化的经验总结

    技术2022-05-19  18

    1.

    List.Count := RowCount;  HighRowIndex := RowCount-1;  for j:=0 to HighRowIndex do  begin    List[j] := ChildClass.Create;  end;//for j

    for j:=0 to HighRowIndex do  begin    List.Add( ChildClass.Create); 

      end;//for j

    要快, 有时95条记录前者不花时间, 而后者要花 0.015s

     

    2.

    TBizObjectClass(ChildClass)很慢, 所以不要在循环里面转换:

    for j:=0 to HighRowIndex dobegin   List.Add( TBizObjectClass(ChildClass).Create);

    end;//for j

    应该改成:

    ChildClass := TBizObjectClass(ChildClass);

    for j:=0 to HighRowIndex dobeginList.Add( ChildClass.Create);

    end;//for j

    注意这里的ChildClass 声明为TClass而不是TBizObjectClass.


    最新回复(0)