Python的shelve模块是否使用内存映射IO?

发布于 2024-08-29 00:49:59 字数 215 浏览 3 评论 0原文

有谁知道Python的shelve模块是否使用内存映射IO?

也许这个问题有点误导。我意识到 shelve 使用底层 dbm 风格的模块来完成它的肮脏工作。底层模块使用 mmap 的可能性有多大?

我正在制作一个数据存储的原型,虽然我意识到过早的优化通常会令人不悦,但这确实可以帮助我理解设计中涉及的权衡。

Does anyone know if Python's shelve module uses memory-mapped IO?

Maybe that question is a bit misleading. I realize that shelve uses an underlying dbm-style module to do its dirty work. What are the chances that the underlying module uses mmap?

I'm prototyping a datastore, and while I realize premature optimization is generally frowned upon, this could really help me understand the trade-offs involved in my design.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

你的笑 2024-09-05 00:49:59

Python 标准库中现有的 dbm 实现都使用“普通”I/O,而不是内存映射。您需要使用内存映射编写自己的 dbmish 实现,并将其与 shelve 集成(直接集成,或者通过 anydbm 更高效地集成) >)。

Existing dbm implementations in the Python standard library all use "normal" I/O, not memory mapping. You'll need to code your own dbmish implementation with memory mapping, and integrate it with shelve (directly, or, more productively, through anydbm).

半枫 2024-09-05 00:49:59

我不确定你想通过问这个问题来了解什么,因为你似乎已经知道答案:这取决于实际使用的 dbm 存储。他们中的一些人会使用 mmap——我希望除了 dumbdbm 之外的所有东西都使用 mmap——但那又怎样呢?搁置中的开销几乎肯定不是在 mmap 与 fileIO 选择中,而是在 pickling 操作中。在任何一种情况下,您都无法自己明智地映射 dbm 文件,因为 dbm 模块可能有自己的奇特锁定(并且它可能不是单个文件,就像它使用 bsddb 时一样。)

如果您只是在寻找灵感对于您自己的数据存储,不要考虑搁置,因为它所做的只是腌制并传递到另一个数据存储。

I'm not sure what you're trying to learn by asking this question, since you already seem to know the answer: it depends on the actual dbm store being used. Some of them will use mmap -- I expect everything but dumbdbm to use mmap -- but so what? The overhead in shelve is almost certainly not in the mmap-versus-fileIO choice, but in the pickling operation. You can't mmap the dbm file sensibly yourself in either case, as the dbm module may have its own fancy locking (and it may not be a single file anyway, like when it uses bsddb.)

If you're just looking for inspiration for your own datastore, well, don't look at shelve, since all it does is pickle-and-pass-along to another datastore.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文