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?
mi6agentAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.