多线程文件访问 [英] Multithreaded file access

查看:131
本文介绍了多线程文件访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个十六进制编辑器程序,当时我正在考虑用户何时尝试打开一个很大的文件(大于3GB).我不希望用户整天坐着等待整个文件在已经加载了一些数据的情况下加载.

I am writing a hex editor program and I was thinking about when a user tries to open a very large file (3GB+). I wouldn't want the user to sit around all day for the whole file to load when it already has some data loaded.

这是我的问题,是否可能让多个线程在不同位置同时读取文件(而不是写入文件),然后一旦某个数据阈值被1读取,该线程就会显示其数据而其他人继续阅读?这会给我带来性能上的改善吗?还是内存带宽会降低我使用多个线程可获得的速度增益?

So here is my question, would it be possible to have multiple threads read the file (not write) simultaneously, at different places, and then then once a certain threshold of data has been read by 1, that thread displays its data while the others continue to read? Would that offer me a performance improvement? Or would memory bandwidths reduce any speed gain I could get from using multiple threads?

推荐答案

对于十六进制编辑器,无需将整个文件读入内存.用户只能查看或修改数据,而不能插入或删除.

For a hex-editor, there is no nead to read the whole file into memory. The user can only view or modify the data but without inserting or deleting.

您可以简单地使用内存映射文件.访问时将自动读取数据,并且仅读取显示的块.这样可以快速滚动并跳转到文件中的任何位置.

You can simply use memory mapped files. The data will be automatically read when accessed and only the chunk displayed will be read. This provide fast scrolling and jumping to any location in the file.

这篇关于多线程文件访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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