binary file manipulations

Reply

Join Date: Jan 2005
Posts: 16
Reputation: akoloff is an unknown quantity at this point 
Solved Threads: 0
akoloff akoloff is offline Offline
Newbie Poster

binary file manipulations

 
0
  #1
Jan 15th, 2005
i want to delete part of a binary file, let's say 12 byte record somewhere in the middle of the file.
i can think of only one thing:
- put the file pointer on the spot
- shuffle all the following records up

there're gotta be a better way ...
any suggestions ???
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 4,009
Reputation: vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice 
Solved Threads: 928
Moderator
vegaseat's Avatar
vegaseat vegaseat is offline Offline
DaniWeb's Hypocrite

Re: binary file manipulations

 
0
  #2
Jan 15th, 2005
Load your file byte by byte into a vector of bytes and erase the elements you want. The vector will adjust itself.
May 'the Google' be with you!
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,625
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 716
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: binary file manipulations

 
0
  #3
Jan 15th, 2005
>there're gotta be a better way ...
There isn't unless your system supports record-oriented files. Any solution will be a variation of what you were thinking of doing. Though naturally, any decent solution will take advantage of block reads and caching to avoid the performance hit of constantly reading and writing to disk.

vegaseat's suggestion is a good one for smaller files, but when working with multi-megabyte/gigabyte files, it's not practical to keep the entire file in memory at once. How you go about solving the problem depends on what files you expect and what kind of performance you're looking for.
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC