python – 什么是参考窃取和借用?

python – 什么是参考窃取和借用?,第1张

概述在阅读 python C / API的文档时,有一些术语涉及引用窃取借用.他们的意思是什么 ? 正如user2864740所评论的那样,这些术语在 Python C API文档的“简介”页面的 Reference Count Details section中定义.以下是相关段落: The reference count behavior of functions in the Python/C 在阅读 python C / API的文档时,有一些术语涉及引用窃取和借用.他们的意思是什么 ?解决方法 正如user2864740所评论的那样,这些术语在 Python C api文档的“简介”页面的 Reference Count Details section中定义.以下是相关段落:

The reference count behavior of functions in the Python/C API is best explained in terms of ownership of references. Ownership pertains to references,never to objects (objects are not owned: they are always shared). “Owning a reference” means being responsible for calling Py_DECREF on it when the reference is no longer needed. Ownership can also be transferred,meaning that the code that receives ownership of the reference then becomes responsible for eventually decref’ing it by calling Py_DECREF() or Py_XDECREF() when it’s no longer needed—or passing on this responsibility (usually to its caller). When a function passes ownership of a reference on to its caller,the caller is saID to receive a new reference. When no ownership is transferred,the caller is saID to borrow the reference. nothing needs to be done for a borrowed reference.

Conversely,when a calling function passes in a reference to an object,there are two possibilitIEs: the function steals a reference to the object,or it does not. Stealing a reference means that when you pass a reference to a function,that function assumes that it Now owns that reference,and you are not responsible for it any longer.

总结

以上是内存溢出为你收集整理的python – 什么是参考窃取和借用?全部内容,希望文章能够帮你解决python – 什么是参考窃取和借用?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/1193112.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-03
下一篇 2022-06-03

发表评论

登录后才能评论

评论列表(0条)

保存