【发布时间】:2014-05-25 20:18:39
【问题描述】:
在 64 位系统上,Python 中的整数占用 24 个字节。这是例如所需内存的 3 倍。 C 表示 64 位整数。现在,我知道这是因为 Python 整数是对象。但是额外的内存有什么用呢?我有我的猜测,但很高兴知道。
【问题讨论】:
-
查看这篇文章:laurentluce.com/posts/python-integer-objects-implementation 和 docs.python.org/2/c-api/structures.html 了解 Python 中的常见对象结构
-
@DNA:谈论 Python 2 基本的
int类型; Python 2 中的long类型(替换 Python 3 中的int类型)仍然有点复杂。 -
请注意,此问题及其答案特定于 CPython 参考实现。其他实现可能有完全不同的内存使用(不过,同样的一般原则适用:需要存储大小和其他对象元数据)。
标签: python object memory int python-internals