944,070 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Unsolved
  • Views: 4473
  • C RSS
Jan 15th, 2005
0

binary file manipulations

Expand Post »
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 ???
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
akoloff is offline Offline
17 posts
since Jan 2005
Jan 15th, 2005
0

Re: binary file manipulations

Load your file byte by byte into a vector of bytes and erase the elements you want. The vector will adjust itself.
Moderator
Reputation Points: 1333
Solved Threads: 1403
DaniWeb's Hypocrite
vegaseat is offline Offline
5,792 posts
since Oct 2004
Jan 15th, 2005
0

Re: binary file manipulations

>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.
Administrator
Reputation Points: 6442
Solved Threads: 1393
Bad Cop
Narue is offline Offline
11,807 posts
since Sep 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: encrypting...pls help me before 17 jan
Next Thread in C Forum Timeline: Variable Variable Names





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC