Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

TStringList restrictions ?

Status
Not open for further replies.

StevenK

Programmer
Jan 5, 2001
1,294
GB
I am using an application that is to work with String Lists (standard TStringList). At present these Strings may be a maximum length of 50 characters and I have a maximum of 250 such Strings at present.
At what point will the application start to become unstable or unreliable to the overloading of TStringLists. Is there a limit that I am restricted by ?
Thanks in advance.
Steve
 
That's a strange problem.
I'm using TStrings and TStringLists a lot, and I haven't noticed some problems at all.

I haven't overloaded TStringLists so many times, but when I did, all seemed to work perfectly.

Is it when you make a new class derrived from TStringList, or when you overloading function etc.?
 
Sorry if my post was not clear. I am not having problems with this but just was curious to know if I could expect to get problems working with a system incorporating the heavy use of TStringLists. It's good to know that you have not faced problems with it - my code is now in place and testing will determine whether this is the way to go with things on this score.
Steve
 
String lists are very useful, but don't forget to 'Clear' and 'Free' them after use or you will get memory problems.

Sorry if you already knew this!!
Steve
 
Does just using 'Free' work - I used to use 'Clear' as well but someone suggested this was over-kill and I have since dropped the habit.
Steve.
 
Its been pointed out (In this forum) that
To make sure that the memory is Free you should loop through all the strings in the list and set them to '', before Freeing.
I Dont know if 'Clear' is required if you do this.
Steve..
 
Delphi uses reference counting for long strings. The following code:
str := 'Ralph the Wonder Llama';
str1 := str;
str2 := str;
str3 := str;

will result in only one memory copy of 'Ralph the Wonder Llama'. All four strings will point to that memory and the string will have a reference count of 4. If you attempt to change one of the copies, for example str3 := str3 + 's'; It will make a copy of the string, add the S to it, and decrement the previous string's reference count to 3. Str3 is now it's own copy of the string.

Keeping the above in mind, I don't think you need to blank out the strings because if you had other references to those strings it would add the overhead of making a new string rather than just reducing the reference count to the string or freeing it outright.

Delphi string handling will free the strings when there are no more references. Freeing your stringlist includes the same steps as calling clear, so it is redundant.

As far as Stringlist restrictions, I think that's a memory thing - you might see performance degradation if you're doing searches but otherwise you're limited to how much memory you have available.

TealWren
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top