How does Python allocate memory for objects of classes derived from C types?

倖福魔咒の 提交于 2020-01-17 06:24:14

问题


Suppose we have created a Python module in C _xxx that contains an extension object xxx, and we do following:

import _xxx

class derived(_xxx.xxx):
    # ...

d = derived()

How does Python allocate memory for d behind the scenes?

Eli Bendersky's article Python object creation sequence is the closest I've found, but it doesn't appear to cover this scenario.

NOTE: there is already an answer HERE: I'm going to ask the author if he will consider migrating his answer here, as it is a good answer to a badly formed question. i.e. He's figured out what question I needed to ask and answered it. But it's going to be difficult for someone else to find the resource, so I think it's better to match it with an appropriate question.

Other answers of course welcome, but just please check the above link first to make sure it isn't already covered! Also any comments to the existing answer, please could you wait until it is relocated (if the author chooses to relocate it).


回答1:


Supplying an answer so that this doesn't appear as an unanswered question (I believe SO's machinery promotes visibility for unanswered questions).

For the answer, please follow the link at the bottom of the question.

If the author relocates the answer here I will delete this stub.



来源:https://stackoverflow.com/questions/27666958/how-does-python-allocate-memory-for-objects-of-classes-derived-from-c-types

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!