File offset

  • Thread starter Thread starter Silan
  • Start date Start date
S

Silan

In our application we store blocks of data in a file, and
keep the file offset of each block in memory. Then we
update the data later using the file offset. S0metimes we
found ourselves writing to wrong location and thus
corrupting the file.

Is this approach (keeping an offset pointer and later re-
access the same data with this pointer) a valid approach?

Can Windows secretly change the relevant offset of data
in the file in the background, for example, in a de-
fragmentation process?
 
This would be better addresses in one of the programming groups, but your
approach seems basically valid IF the file is exclusively accessible by only
one process/instance of your program, i..e there is no possibility of file
modification outside your program. A process like degragmentaion wouldn't
affect the validity of the offset as physical location of the clusters is
transparent to file management calls. Are you careful that no function of
your own program can invalidate the saved offset (eg. a block deletion)?,
that you are always seeking from the 0th byte?, that your file handle
remains valid?
 
Back
Top