插入文本在特定的文件中使用Win32 API的偏移 [英] Inserting text into file at specific offset using Win32 API

查看:222
本文介绍了插入文本在特定的文件中使用Win32 API的偏移的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要寻找一种方法,使快速的修改,大型的多千兆字节的文件。不要在Win32 API支持,而无需从一开始还是从变化的偏移重写整个文件回磁盘在一个特定的偏移将文本插入到一个文件的能力吗?

I am looking for a way to make speedy modifications to large multi-gigabyte files. Do the Win32 API support the ability to insert text into a file at a specific offset without having to rewrite the entire file back to disk from the very beginning or from the offset of the change?

考虑一个例子。比方说,我们有文字的test的文件是1 GB的大小一遍又一遍地重复。如果我想去到500 MB偏移和插入文本新,有没有插入,而无需从头开始重写整个文件,和/或无需重写它的最后500 MB的一种方式?

Consider an example. Let's say we have the text "test" repeated over and over in a file that is 1 GB in size. If I want to go to the 500 MB offset and insert the text "new", is there a way to insert it without having to rewrite the entire file from the beginning, and/or without having to rewrite the last 500 MBs of it?

是否可以使用Win32 API的呢?如果不是,有什么策略来优化像这样的文本插入操作以最大限度地提高速度?

Can it be done using Win32 API? If not, are there any strategies to optimize a text insertion operation like this to maximize speed?

推荐答案

有方法仅重写部分的之后的插入点,但通常不 - 要在一个特定点插入一些一个文件,你必须重新编写点之后的一切。

There are methods to rewrite only the portion after the insertion point, but generally, no - to insert something at a particular point in a file, you must re-write everything after that point.

这可以归结为文件存储在磁盘上的方式 - 通常块,使得这种操作要么不可能,要么不容易的。为99%的情况,这并不重要,因此,API不暴露这样做的一种方式。

This boils down to the way files are stored on disk - typically in chunks, such that this operation is either not possible or not easy. For 99% of the cases, this doesn't matter, so the API doesn't expose a way of doing this.

如果您有控制文件格式,你可以工程师的方式,这样可以将数据写入到文件的末尾,但有一定的跟踪数据说这东西真的属于这里。

If you have control over the file format, you can engineer ways such that you can write data to the end of the file, but have some tracking data to say "this stuff really belongs here".

这篇关于插入文本在特定的文件中使用Win32 API的偏移的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆