将 open(Filename, {delayed_write, Size, Delay}) 与索引结合起来
如何将 open(Filename, {delayed_write, Size, Delay}) 与该数据写入位置的索引结合起来?
我想等到收到一定量的数据,然后将其写入文件中的某个位置。
{read_ahead, Size} 是否与 {delayed_write, Size, Delay} 相反?我想读取一定量的数据来发送它。
谢谢
How can I combine a open(Filename, {delayed_write, Size, Delay}) with an index on where to write this data to?
I want to wait until I receive a certain amount of data and then write it to a position in the file.
Also is {read_ahead, Size} the opposite of {delayed_write, Size, Delay}? I would like to read a certain amount of data to send it.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
read_ahead 与delayed_write 相反,因为读取与写入相反。
如果您想读取并发送更大的内存块,则不需要 read_ahead,只需读取大块并发送它们(此处保存的操作系统调用不多)。
来自 read_ahead 上的 file:open/2 联机帮助页:
打开时不需要指定和索引。只需使用 pwrite/3 或 position/2 和 write/2。
但是在文件的不同位置写入可能只会减少
delayed_write
的增益,因为(也是 文件:open/2):如果您有多个位置的大量数据,请将它们收集在
{Location, Bytes}
列表中,并时不时用 file:pwrite/2 一口气完成。这可以映射到非常高效的writev(2)
系统调用,一次性写入多个块。read_ahead is kind of the opposite of delayed_write in the sense that reading is the opposite of writing.
If you want to read and send bigger chunks of memory you don't need read_ahead, just read big chunks and send them (not many os calls to save here).
From the file:open/2 manpage on read_ahead:
You don't need to specify and index when opening. Just use pwrite/3 or a combination of position/2 and write/2.
But writing in different positions of the file might just reduce the gain of
delayed_write
since (also manpage of file:open/2):If you have chunks of data for several positions collect them in a list of
{Location, Bytes}
and from time to time write them with file:pwrite/2 all in one go. This can map to very efficientwritev(2)
system call that writes several chunks in one go.