Python如何为从C类型派生的类的对象分配内存? [英] How does Python allocate memory for objects of classes derived from C types?

查看:142
本文介绍了Python如何为从C类型派生的类的对象分配内存?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我们在C _xxx中创建了一个包含扩展对象xxx的Python模块,然后执行以下操作:

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()

Python如何在后台为d分配内存?

How does Python allocate memory for d behind the scenes?

Eli Bendersky的文章 Python对象创建序列是我找到的最接近的,但似乎无法涵盖这种情况.

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).

推荐答案

提供答案,以免出现未解决的问题(我相信SO的机制可以提高未解决问题的可见性).

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.

这篇关于Python如何为从C类型派生的类的对象分配内存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆