gpt4 book ai didi

erlang - dets 会在使用 ram_file 选项查找时执行磁盘读取吗?

转载 作者:行者123 更新时间:2023-12-01 15:30:01 25 4
gpt4 key购买 nike

DETS Erlang 文档中描述了一个选项 ram_file

open_file(name, args)

{ram_file, boolean()} - Whether the table is to be kept in RAM. Keeping the table in RAM can sound like an anomaly, but can enhance the performance of applications that open a table, insert a set of objects, and then close the table. When the table is closed, its contents are written to the disk file. Defaults to false.

这将在插入或更新后在磁盘上执行保存

如果我会用呢打开 - 然后查找 - 然后关闭?

最佳答案

我没有查看文档,但我假设这意味着 VM 将打开文件并可能mmap 它,所以它一直保存在内存,它会与磁盘上的文件同步,但我认为更改仍然可以在缓存中结束,因此不会立即写入磁盘。如果您想确保所有更改都已刷新到磁盘,请使用 dets:sync/1调用表以强制刷新数据,这在文档中有明确说明:

This also applies to tables that have been opened with flag ram_file set to true. In this case, the contents of the RAM file are flushed to disk.

它不会在每次查找后打开或关闭文件,但它会保持打开状态,直到 dets:close/1 不会在给定的表上调用。另一方面,为每次查找打开和关闭表可能代价高昂,因此这会使整个 DETS 的使用变得毫无意义。

关于erlang - dets 会在使用 ram_file 选项查找时执行磁盘读取吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59304443/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com