Python有静态对象、堆栈对象和堆对象吗?

2024-04-27 02:44:04 发布

您现在位置:Python中文网/ 问答频道 /正文

来自编程语言语用学,斯科特

Object lifetimes generally correspond to one of three principal storage allocation mechanisms, used to manage the object’s space:

  1. Static objects are given an absolute address that is retained throughout the program’s execution.

  2. Stack objects are allocated and deallocated in last-in, first-out order, usually in conjunction with subroutine calls and returns.

  3. Heap objects may be allocated and deallocated at arbitrary times. They require a more general (and expensive) storage management algorithm.

C语言有静态对象、堆栈对象和堆对象。在

Python有静态对象、堆栈对象和堆对象吗?在

我看到了in another postCPython分配堆上的所有对象。这是否意味着Python中的所有对象都是堆对象?在

但是Python也有静态方法。Python中的静态方法是静态对象吗?在

谢谢。在


Tags: andtheto对象inobjectsobject堆栈
1条回答
网友
1楼 · 发布于 2024-04-27 02:44:04

Python对象大多是堆对象,但是在CPython中有一些特殊的PyObject singleton值在C中是static,但这是实现细节。例如,通常的内置类型具有静态存储持续时间。据我所知,没有堆栈(Python)对象。在

静态存储持续时间与静态方法完全无关。在

相关问题 更多 >