在OS块缓冲区中保留一个文件

编程入门 行业动态 更新时间:2024-10-22 23:45:36
本文介绍了在OS块缓冲区中保留一个文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我需要在操作系统块缓存中保留尽可能多的大文件,尽管它大于我可以放在内存中,而且我不断读取另一个非常大的文件。 ATM我将从系统缓存中删除大块重要的文件,当我流读取形式另一个文件。

解决方案

在一个POSIX系统如Linux或Solaris,请尝试使用posix_fadvise。

在流文件上,执行如下操作:

posix_fadvise(fd,0,0,POSIX_FADV_SEQUENTIAL); while(bytes> 0){ bytes = pread(fd,buffer,64 * 1024,current_pos); current_pos + = 64 * 1024; posix_fadvise(fd,0,current_pos,POSIX_FADV_DONTNEED); $ b $ p $ b你可以将POSIX_FADV_WILLNEED应用到你的其他文件, 。 现在,我知道Windows Vista和Server 2008也可以做内存优先级的漂亮技巧。像XP这样的老版本也可以做更多的基本技巧。但是我不知道这些功能是否在我头上,也没有时间查看它们。

I need to keep as much as I can of large file in the operating system block cache even though it's bigger than I can fit in ram, and I'm continously reading another very very large file. ATM I'll remove large chunk of large important file from system cache when I stream read form another file.

解决方案

In a POSIX system like Linux or Solaris, try using posix_fadvise.

On the streaming file, do something like this:

posix_fadvise(fd, 0, 0, POSIX_FADV_SEQUENTIAL); while( bytes > 0 ) { bytes = pread(fd, buffer, 64 * 1024, current_pos); current_pos += 64 * 1024; posix_fadvise(fd, 0, current_pos, POSIX_FADV_DONTNEED); }

And you can apply POSIX_FADV_WILLNEED to your other file, which should raise its memory priority.

Now, I know that Windows Vista and Server 2008 can also do nifty tricks with memory priorities. Probably older versions like XP can do more basic tricks as well. But I don't know the functions off the top of my head and don't have time to look them up.

更多推荐

在OS块缓冲区中保留一个文件

本文发布于:2023-10-23 02:07:38,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1519423.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:区中   文件   OS

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!