如何fseek的()在文件系统中实现的? [英] How is fseek() implemented in the filesystem?

查看:216
本文介绍了如何fseek的()在文件系统中实现的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是不是一个纯粹的编程问题,但它的影响fseek的使用(程序的性能),因此它知道它是如何工作是很重要的。一个小声明,这样它不会关闭。

This is not a pure programming question, however it impacts the performance of programs using fseek(), hence it is important to know how it works. A little disclaimer so that it doesn't get closed.

我不知道它是多么有效率的文件中间插入数据。假如我有1MB的数据文件,然后我插入的512KB偏移东西。如何有效的将是进行比较,在文件的最后追加我的数据?只是为了让这个例子完整的可以说我想插入数据的16KB。

I am wondering how efficient it is to insert data in the middle of the file. Supposing I have a file with 1MB data and then I insert something at the 512KB offset. How efficient would that be compared to appending my data at the end of the file? Just to make the example complete lets say I want to insert 16KB of data.

据我所知,答案取决于文件系​​统不同而不同,但我认为在普通文件系统中使用的技术是非常相似的,我只是想获得它的正确概念。

I understand the answer varies depending on the filesystem, however I assume that the techniques used in common filesystems are quite similar and I just want to get the right notion of it.

推荐答案

(声明:我不会只是一些提示添加到这个有趣的讨论)
恕我直言,有一些事情要考虑到:

(disclaimer: I wont just to add some hints to this interesting discussion) IMHO there are some things to take into account:

1)fseek的不是主系统的服务,但是一个库功能。为了评估其性能,我们必须考虑文件流库是如何实现的。在一般情况下,该文件I / O库补充在用户空间中的缓冲层,所以fseek的性能可能相当不同,如果目标位置的内部或当前缓冲区之外。此外,该系统服务的I / O libary用途可能有很大的差异。即在某些系统上图书馆广泛使用的文件内存映射如果可能的话。

1) fseek is not a primary system service, but a library function. To evaluate its performance we must consider how the file stream library is implemented. In general, the file I/O library adds a layer of buffering in user space, so the performance of fseek may be quite different if the target position is inside or outside the current buffer. Also, the system services that the I/O libary uses may vary a lot. I.e. on some systems the library uses extensively the file memory mapping if possible.

2),正如你所说,不同的文件系统的行为可能在一个非常不同的方式。特别是,我会期望一个文件系统的事务必须做一些非常聪明的,也许昂贵的是在一个文件中间ppared来中止写入操作的可能回滚$ P $。

2) As you said, different filesystems may behave in a very different way. In particular, I would expect that a transactional filesystem must do something very smart and perhaps expensive to be prepared to a possible rollback of an aborted write operation in the middle of a file.

3)现代化OS'es有非常积极的缓存algorythms。一个fseeked文件很可能是已经$缓存p $ psent,所以操作变得快得多。但是,他们可能会降低很多,如果被其他进程所产生的整体文件系统活动变得重要起来。

3) The modern OS'es have very aggressive caching algorythms. An "fseeked" file is likely to be already present in cache, so operations become much faster. But they may degrade a lot if the overall filesystem activity produced by other processes become important.

有何评论?
 问候

Any comments? Regards

这篇关于如何fseek的()在文件系统中实现的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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