python的变量位于堆内存吗_在Python中如何为变量分配内存?

Python does a lot of allocations and deallocations. All objects,

including "simple" types like integers and floats, are stored on the

heap. Calling malloc and free for each variable would be very slow.

Hence, the Python interpreter uses a variety of optimized memory

allocation schemes. The most important one is a malloc implementation

called pymalloc, designed specifically to handle large numbers of

small allocations. Any object that is smaller than 256 bytes uses this

allocator, while anything larger uses the system's malloc.Memory allocation works at several levels in Python. There’s the

system’s own allocator, which is what shows up when you check the

memory use using the Windows Task Manager or ps. Then there’s the C

runtime’s memory allocator (malloc), which gets memory from the system

allocator, and hands it out in smaller chunks to the application.

Finally, there’s Python’s own object allocator, which is used for

objects up to 256 bytes. This allocator grabs large chunks of memory

from the C allocator, and chops them up in smaller pieces using an

algorithm carefully tuned for Python.

特别是浮点数:floats also use an immortal & unbounded free list.

所以不,只有在pythons free list中没有更多可用的float点时才会分配它,这取决于程序中以前的float使用情况。在

归根结底,python正在为您进行内存管理,因此即使您的问题得到了可靠的回答,也不会给您带来太多的洞察力。在

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值