*Summarization:
Please check the knowledgeable comments from the Delphi experts. Specifically for me, I would try to use old TList/TObjectList as David suggested, and use hard-cast and TObjectList.List property as A.Bouchez suggested. I will try TDynArray when refactoring in future.
=====================================================================
Say that I have a TAtom
class as defined in the following code. There are about hundreds
up to thousands
of TAtom instances at run time, stored in a dynamic array
for now. At run time, I need to do simple float math on TAtom.X/Y/Z
of all the existing TAtom instances more than 30
times per second.
Now, I need to add the ability of adding
, inserting
, deleting
of TAtom instances at run time. It seems that my choices are (1) request a big array; (2) stick to dynamic array and manually SetLength; (3) switch to regular TList; (4) switch to regular TObjectList.
I want to avoid (1) unless it is necessary, because I then have to change quite a lot function signatures. (2) looks not good either, because TList/TObjectList seems born for this task. However, because type-casting is needed using the regular TList/TObjectList, could some one comment on the possible performance hit? I mean, it would be best if the performance burden could be estimated before I rewrites the code. If the performance will drop noticeably, is there other technics that I could use?
Furthermore, I am wondering if there is performance difference between using TList and TObjectList?
TAtom = class
public
ElementZ: Integer;
X, Y, Z: Extended;
other variables: other types;
end;
TAAtom = array of TAtom;
return on investment
in my situation? – Nectarinerandom access
. But I dosequential access
a lot. For example, for each batch of simple float math calculation, I need to iterate through the instances. I assume thelinked list
data structure is not as good asarray
insequential access
? – Nectarine