• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 155
  • Last Modified:

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?
0
mi6agent
Asked:
mi6agent
1 Solution
 
kretzschmarCommented:
i would guess
example 2 uses less memory and is faster
0
 
Ivanov_GCommented:
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...
0
 
BlackTigerXCommented:
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
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
robert_marquardtCommented:
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.
0
 
mi6agentAuthor Commented:
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.
0
 
robert_marquardtCommented:
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.
0
 
calinutzCommented:
Why not test both methods and put a timer on the form and check the amount of time the whole process requires on both cases?
So much about speed....
0
 
robert_marquardtCommented:
With 5000 elements the speed is mainly determined by the file IO.
0
 
TiborKiCommented:
Use databases, it's most simple way!
0
 
TiborKiCommented:
And fastest way!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now