If you do use TStringList, you may want to call Capacity := 500000. Otherwise, it will continually need to reallocate memory as you add the items since the internal array is dynamically allocated. The delta is one quarter of the current capacity, so you may want to override the Grow method to be a bit more intelligent than "Delta := Capacity div 4"
 
However, if you can guarantee that the strings are not going to be more than 150 bytes (or 255 bytes for that matter) then you might consider creating your own descendant of TStrings thats uses ShortStrings. This will save the overhead of using Long Strings if you can allocate 500,000 x 150 bytes all at once. (thats 75-127MB :-o ).
 
The other advantage of using TStrings descendant is the Streaming methods are available. I guess you wouldn't want to pass the TStrings to a TListBox or anything, huh ;-). But for that amount of memory/items, I would definately spend time doing some performance tests on various solutions, and a generic solution (like TStringList) probably wouldn't fit the job.
 
If the strings are already allocated memory somewhere else, then you can probably get away with using a TList to store PChar pointers. Once again, watch the Capacity and Delta values.
 
Good Luck
Paul Grimstrup
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]On Behalf Of Myles Penlington
Sent: Thursday, 1 November 2001 5:21 pm
To: Multiple recipients of list delphi
Subject: RE: [DUG]: Dynamic Arrays V Strings Lists

Dynamic array will always be faster.
The under lying implementation of TList is really a dynamic array also, so the only overhead is the accessor method and range check performed.
Myles.
 
-----Original Message-----
From: David Smith [mailto:[EMAIL PROTECTED]]
Sent: Thursday, 1 November 2001 5:01 p.m.
To: Multiple recipients of list delphi
Subject: [DUG]: Dynamic Arrays V Strings Lists

Hi,
 
Any one have ideas or experience if Dynamic arrays or string\object lists is faster for accessing an element.
 
Am developing an application where microns (maybe microseconds) for accessing an item in a list over 500 000 items (about 1500 bytes each) based on an index is very important. 
 
Thanks,
David.

Reply via email to