Python如何处理内存? [英] How does Python handle memory?

查看:103
本文介绍了Python如何处理内存?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在查看内存数据库 –我在想,Python如何处理与连接无关的IO(甚至是与数据无关);例如,散列,集合等;这是某个地方的配置,还是根据资源进行动态管理?是否有简便"的方法来查看资源在真实程序中所具有的效果,并模拟不同硬件设置对性能的影响?

I've been looking at a in-memory database -- and it got me thinking, how does Python handle IO that's not tied to a connection (and even data that is); for example, hashes, sets, etc.; is this a config somewhere, or is it dynamically managed based on resources; are there "easy" ways to view the effect resources are having on a real program, and simulate what the performance hit would be differing hardware setups?

注意:如果有关系, Redis 是内存中的数据存储我在看有一个针对Redis数据类型的包装器的实现,因此它们模仿了Python中找到的数据类型.

NOTE: If it matters, Redis is the in-memory data store I'm looking at; there's an implementation of a wrapper for Redis datatypes so they mimic the datatypes found in Python.

推荐答案

Python分配应用程序要求的所有内存.没有太多政策空间.唯一的问题是何时释放内存. (C)Python立即释放不再引用的所有内存(这也是不可调整的).垃圾收集器释放仅从自身(即周期)引用的内存;这具有可调的设置.

Python allocates all memory that the application asks for. There is not much room for policy. The only issue is when to release memory. (C)Python immediately releases all memory that is not referenced anymore (this is also not tunable). Memory that is referenced only from itself (ie. cycles) are released by the garbage collector; this has tunable settings.

操作系统决定将一些内存写入页面文件.

It is the operating system's decision to write some of the memory into the pagefile.

这篇关于Python如何处理内存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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