Link to home
Start Free TrialLog in
Avatar of mrquija
mrquija

asked on

Copying a files contents

I need to delete a row from a file with many rows in it.  Does anyone have any suggestions as to THE MOST EFFICIENT/FASTEST algorithm KNOWN TO MANKIND on how to do this?  I have some ideas, such as simply string copying from one file to the other and omitting the row that I dont want...but I dont know if that's THE FASTEST in the entire UNIVERSE.  You know, they should make a search engine on this experts-exchange forum, I'm sure this question has been asked before, but I'm way too lazy to go through 2000 paq to  perhaps find the one I need.  Thanks to all.
Avatar of KangaRoo
KangaRoo

42
Ask Mirkwood.
Avatar of mrquija

ASKER

not sure what you mean by your comment of Asking mirkwood.
Avatar of mrquija

ASKER

by the way, I'm not asking for code...merely just suggestions/practical ideas for fastest completion of this task.
I can't tell you about the fastest method in the Universe. What you sketched seems ok.
You could add some info at the beginning of a record, like wether the record is in use or free (deleted) and the size of the record (not needed for fixed lenght). Once in a while you clean up the file by copying only used records into a new file.
Use memory mapped files
Since you're not asking for code...
Yes, copy line by line -- omiting the line you don't want.

Another techniqe would be to mark the first character with an ID you know means "don't use this line" -- such as changing
This is neat
   to
£his is neat
That was put in as comment Triskelion.

actually that depands on ur file structure !!! if its a sequential file then this is the approach .. in case u are the creator of the file .. then u can make this even faster ..

how about storing Linked List in a file with the pointer as file offset ..

regards
Avatar of mrquija

ASKER

Kangaroo gets points
ASKER CERTIFIED SOLUTION
Avatar of KangaRoo
KangaRoo

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