Is there a fast way to copy a generic TList?
Copy.Capacity := List.Count;
for Item in List do
Copy.Add (Item);
is very slow. There seems to be no way to use CopyMemory since I can’t get the memory adress of the internal array (which is obvious from an information hiding viewpoint). I miss something like
List.Copy (Copy);
which uses the knowledge of the internal representation to improve performance. Can it be done?
For the generic
TList<T>it is simply not possible to implement the function you want. That’s because copy the contents ofTmay involve more than a simple memory copy. IfTcontains any managed types (i.e. strings, interfaces etc.) then the reference counts on those managed objects must be incremented.Tdoes contain managed types then I doubt that you can do much better then the code you already have.Tdoes not contain any managed types then a memory copy is viable but you will need to create your own class to encapsulate this list sinceTList<T>is not appropriate.