最快的方式来擦除C ++中的部分文件 [英] Fastest way to erase part of file in C++

查看:318
本文介绍了最快的方式来擦除C ++中的部分文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道哪个是最快的方式来擦除c ++中的文件的一部分。

I wonder which is the fastest way to erase part of a file in c++.

我知道写第二个文件的方式,跳过你想要的部分。

I know the way of write a second file and skip the part you want. But i think is slow when you work with big files.

关于数据库系统,他们如何快速删除记录?

What about database system, how they remove records so fast?

推荐答案

数据库系统通常只是将删除的记录标记为已删除,无需物理恢复未使用的空间。它们可以稍后重用被删除记录占用的空间。这就是为什么他们可以快速删除数据库的一部分。

Database systems typically just mark deleted records as deleted, without physically recovering the unused space. They may later reuse the space occupied by deleted records. That's why they can delete parts of a database quickly.

快速删除文件的一部分的能力取决于您要删除的文件部分。如果要删除的文件部分位于文件末尾,则可以使用操作系统调用来截断该文件。

The ability to quickly delete a portion of a file depends on the portion of the file you wish to delete. If the portion of the file that you are deleting is at the end of the file, you can simply truncate the file, using OS calls.

删除文件的一部分从中间可能是耗时的。您的选择是向前移动文件的剩余部分,或将整个文件复制到新位置,跳过已删除的部分。对于大文件,任一种方式都可能是耗时的。

Deleting a portion of a file from the middle is potentially time consuming. Your choice is to either move the remainder of the file forward, or to copy the entire file to a new location, skipping the deleted portion. Either way could be time consuming for a large file.

这篇关于最快的方式来擦除C ++中的部分文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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