technical question about save and save as commands

Help on how to use HxD.
Post Reply
Posts: 1
Joined: 21 Jul 2023 22:18

technical question about save and save as commands

Post by javski »

Hello, my name is Javid, I am a self taught musician. I have been using your hex editor to experiment with my audio and video files. That's not what I wanna talk about though. (If you are interested in my experiments I can provide you a link, lol )
My question is the following:
let's say I open a wav file in the hex editor. Let's say I do some changes and then hit save. If I understand correctly changes are saved to the original file.
Then let's say I do the same thing (open wav file, do some changes) but then this time I save it as a new file. If I understand correctly, this time it doesn't just add the changes, but saves the whole code as a new file (from the coding perspective). Is that so?
Thanks for your help in advance, this would greatly help me in my further experiments. :D
Site Admin
Posts: 1454
Joined: 12 Mar 2005 14:15

Re: technical question about save and save as commands

Post by Maël »

Hi Javid,

Sure let's see those experiments :)

Regarding your question. So you have modified a file, and once you save it, and the other time you chose save as.

The file "save as" indeed creates a whole new file with the complete contents, it's a copy of the entire data stream (original file + applied changes). Maybe some clever file system could use a copy-on-write scheme to save space on the hard disk, or use compression to avoid duplicate data-blocks (parts that are the same in the original and "saved as" file). But from the perspective of HxD, yes, "save as" creates an entirely new file copying the file contents of the old file, and applying the changed that are kept in memory.

When you simply save, HxD will try to only write the changes, and keep the unchanged data where it was, unless you inserted data, then also the old data has to be rewritten, since its position has moved.

Internally, there is a TEditStream class that handles insertions, deletions, overwriting, using a tree datastructure to keep track of changes relative to the original file on disk. The hex editor component/control will read a portion from this TEditStream and display the data.
Post Reply