Link to home
Start Free TrialLog in
Avatar of mi6agent
mi6agent

asked on

Just advice needed....

I just need some advice rather than code on what is the best of the two follwoing approaches.

(each record in the file is 2500 bytes)

Example 1:

* Load in 5000 records from a file of records into a TList structure
* Search through the 5000 records and delete any no longer required
* Save the records back to file

OR

Example 2:

* Load in 5000 records from a file of records into an array
* Search through the 5000 records and delete any no longer required
* Save the records back to file

My question is: Which is the best method to use (some reasons on your choice would help) - ie: memory saving, speed, etc?
Avatar of kretzschmar
kretzschmar
Flag of Germany image

i would guess
example 2 uses less memory and is faster
In TList is better, because it will contain object with type - your records. Probably the array will need some more coding.

If the records are Strings only - use TStringList.LoadFromFile...
Avatar of BlackTigerX
BlackTigerX

TList gives you a lot more flexibility for many things, it has the methods for loading, deleting and saving already built in, if you use the array you would have to code that yourself
besides, with TList you would be "ready" to load not only from a file, but pretty much from anything using a TStream

I would go for the TList

best regards
Using an array you would have to move the folowing elements when deleting. TList does that for you.
The real trick is not to delete any element. Create an array of Boolean where you store the deletion info.
Real deletion is done by not saving the element back to file.
Avatar of mi6agent

ASKER

will leave this open to see if anyone else has a point to add.

I can see that the TList would add a small amount of overhead - and although has methods for loading, deleting built in i wonder if they would be faster to work with than coding the routines myself - besides, deleting a record from a TList requires that code is written to free the memory of the record too therefore speed would be reduced.

 Maybe i'm wrong - which is why i asked for pointers from experts.
Forgot, array of TElement is faster because only one allocation happens. From the file size you can determine the number of elements beforehand.
Memory consumption is of no interest with only 5000 elements. 5000*2500 Bytes is what you need always.
The array of Boolean needs just 5000 Bytes = 2 Elements.
ASKER CERTIFIED SOLUTION
Avatar of calinutz
calinutz
Flag of Romania 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
With 5000 elements the speed is mainly determined by the file IO.
Use databases, it's most simple way!
And fastest way!