954,479 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

binary file manipulations

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 ???

akoloff
Newbie Poster
17 posts since Jan 2005
Reputation Points: 10
Solved Threads: 0
 

Load your file byte by byte into a vector of bytes and erase the elements you want. The vector will adjust itself.

vegaseat
DaniWeb's Hypocrite
Moderator
5,986 posts since Oct 2004
Reputation Points: 1,345
Solved Threads: 1,417
 

>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.

Narue
Bad Cop
Administrator
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You