-->

How does Python allocate memory for objects of cla

2019-09-04 05:57发布

问题:

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.