Recently i have been developing an application and wanted to have a collections of several types. I don't want to declare and implement a new collection class for it's type. So, i thought of going with generics, but wasn't sure about the performance of Generics compared to normal typed instances. Performance is the major thing that i am looking at. My application is time critical and even loosing few 100 milliseconds is also not advisable.
I am using Delphi XE3
For eg:
ICollectionItem = interface
function GetID : string;
property ID : string read GetId;
end;
TGenericCollection<T: ICollectionItem> = class
function Add(T) : Integer;
end;
compared to
TSomeClass = class(TInterfacedObject, ICollectionItem)
function GetId : string;
end;
TSomeClassList = class
function Add(item : TSomeClass) : Integer;
end;
SizeOf(T) + 1
at compile time) aren't. – Granados"Using Generic containers in Delphi XE - always?"
. Better performance since optimization can do a better job. See also"Overview of Generics"
. At instantiation there might be a performance penalty. – Gelatin