0

I want to insert into a large file, but I do not want to copy the part that is behind the insertion point. Is there a way to do this (of course with restrictions from the file system)? I'm thinking along the lines that the file system is normally organized in blocks & inserting a full block between 2 blocks should be cheap. Does anyone know if and how this could be done on win32 systems?

Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055
Tobias Langner
  • 10,634
  • 6
  • 46
  • 76

2 Answers2

0

The simple answer is no. The OS doesn't support this, and for file systems like those used by Windows or Unix, it's difficult to see how they could. It's true that physically, the file itself is split into allocation blocks, but the size of these blocks varies from drive to drive, not to mention from file system to file system (and you'll often have several different file systems mounted), and the utility of a function which allows you to insert, but only multiples of n bytes, at a position which is itself a multple of n bytes, probably seems of too limited utility to be worthwhile. And supporting it would still entail copying, since the blocks containing the pointers to these blocks would have to be copied.

James Kanze
  • 150,581
  • 18
  • 184
  • 329
-1

You can truncate, append new data, append remaining old data.

Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055
  • You'd still have to read the old data at the end first. And the results wouldn't be pleasant if your program was terminated right after the truncation. – James Kanze Nov 04 '13 at 14:07
  • @JamesKanze: No matter what you do, you can break it. Pull the power while the hard disk cache is being emptied and let me know what happens – Lightness Races in Orbit Nov 04 '13 at 14:10
  • The usual techniques always leave a consistent state somewhere. You don't remove or modify the source until the destination has been successfully written. – James Kanze Nov 04 '13 at 14:39
  • @JamesKanze: It depends what you're doing. If you're manipulating a 500GB file then, no, you probably don't leave a consistent state somewhere unless you count your daily backups _[disclaimer: I entirely jest]_ – Lightness Races in Orbit Nov 04 '13 at 14:40