Link to home
Start Free TrialLog in
Avatar of scoopbh
scoopbh

asked on

Using, saving and loading strings

Hi,

I wish to use some data structure to store a var called "name" that is a string, I need to store about 25.000 different names (i.e 'Joh Paul Sartre') in the memory, then save it to a file, then load it back in memory. I tried with stringlist but it consumes a lot of ram memory (also very slow to access), the same with trecord, what is the best way to do that? Code is welcome. Ā (I don't want to use any database componnent, I wish to alocate it in vars).

Avatar of Scay7
Scay7
Flag of South Africa image

Tried an Ini File ? or do you not want to use any files ?

Peace Scay7
Avatar of Russell Libby

Regarding the string list, how much memory do you think it is using (and moreover, how are you determining this?). If you have 25000 items, each an average of say 20 bytes, then you are you looking at roughly 700KB of memory (data and list management) for the string list. And how were you acessing the items in the list? Sequentially by index, or were you trying to perform finds on the list? If you were attempting a find, hopefully the list was sorted, else the list does sequential scans. A little more information would be helpful, but from the sounds of it, a stringlist (used correctly) should work fine for what you are attempting to do.

Regards,
Russell


you can use XML as database/storage file
example can be found here:
http://www.skch.net/columns/xml_delphi.html
ASKER CERTIFIED SOLUTION
Avatar of TheRealLoki
TheRealLoki
Flag of New Zealand image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You said (I don't want to use any database componnent, I wish to alocate it in vars). Can you tell the reason why?

I recommend to go with TClientDataset.
I suppose it would depend if he wants to ship the midas.dll with his application or not atul_parmar
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
TMemIniFile reads the ini once, and bufers it all in nested stringlists. It then caches changes.
Unfortunately, scoopbh is concerned about memory usage with his big lists.