简体   繁体   English

Python如何处理内存?

[英]How does Python handle memory?

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); 我一直在寻找一个内存数据库 - 它让我思考,Python如何处理与连接无关的IO(甚至是数据); 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? 是否有“简单”的方法来查看资源对真实程序的影响,并模拟性能受到影响的不同硬件设置?

NOTE: If it matters, Redis is the in-memory data store I'm looking at; 注意:如果重要, Redis是我正在查看的内存数据存储; there's an implementation of a wrapper for Redis datatypes so they mimic the datatypes found in Python. 有一个Redis数据类型包装器的实现,因此它们模仿Python中的数据类型。

Python allocates all memory that the application asks for. Python分配应用程序要求的所有内存。 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). (C)Python立即释放所有未被引用的内存(这也是不可调的)。 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. 操作系统决定将一些内存写入页面文件。

Not exactly what you're asking for, but Dowser is a Python tool for interactively browsing the memory usage of your running program. 不完全是你所要求的,但是Dowser是一个Python工具,用于交互式浏览正在运行的程序的内存使用情况。 Very useful in understanding memory usage and allocation patterns. 在理解内存使用和分配模式方面非常有用。

http://www.aminus.net/wiki/Dowser http://www.aminus.net/wiki/Dowser

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM