📄 128.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META NAME="Robots" content="INDEX,NOFOLLOW">
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<TITLE>Safari | Python Essential Reference, Second Edition -> Reference Counting</TITLE>
<LINK REL="stylesheet" HREF="oreillyi/oreillyM.css">
</HEAD>
<BODY bgcolor="white" text="black" link="#990000" vlink="#990000" alink="#990000" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<table width="100%" cellpadding=5 cellspacing=0 border=0 class="navtopbg"><tr><td><font size="1"><p class="navtitle"><a href="2.html" class="navtitle">Linux/Unix</a> > <a href="0735710910.html" class="navtitle">Python Essential Reference, Second Edition</a> > <a href="121.html" class="navtitle">B. Extending and Embedding Python</a> > <span class="nonavtitle">Reference Counting</span></p></font></td><td align="right" valign="top" nowrap><font size="1"><a href="main.asp?list" class="safnavoff">See All Titles</a></font></td></tr></table>
<TABLE width=100% bgcolor=white border=0 cellspacing=0 cellpadding=5><TR><TD>
<TABLE border=0 width="100%" cellspacing=0 cellpadding=0><TR><td align=left width="15%" class="headingsubbarbg"><a href="127.html" title="Error Handling"><font size="1">< BACK</font></a></td><td align=center width="70%" class="headingsubbarbg"><font size="1"><a href="popanote.asp?pubui=oreilly&bookname=0735710910&snode=128" target="_blank" title="Make a public or private annnotation">Make Note</a> | <a href="128.html" title="Use a Safari bookmark to remember this section">Bookmark</a></font></td><td align=right width="15%" class="headingsubbarbg"><a href="129.html" title="Calling Python from C"><font size="1">CONTINUE ></font></a></td></TR></TABLE>
<a href="5%2F28%2F2002+9%3A09%3A38+PM.html" TABINDEX="-1"><img src=images/spacer.gif border=0 width=1 height=1></a><font color=white size=1>155117184014003188065099048180054212144238241179195140058238111161105095080115231005169016</font><a href="read9.asp?bookname=0735710910&snode=128&now=5%2F28%2F2002+9%3A09%3A38+PM" TABINDEX="-1"><img src=images/spacer.gif border=0 width=1 height=1></a><br>
<FONT>
<h3>Reference Counting</h3>
<p>Unlike programs written in Python, C extensions have to manipulate the reference count of Python objects. This is done using the following macros:</p>
<P><TABle boRDER="1" cellSPACing="0" cellpadding="1" width="100%">
<cOlgRoup Span="2">
<tR>
<th vALIGn="top">
<fonT SIZe="2">
<p><b>Macro</b></P>
</FONt></th>
<tH VALign="top">
<font size="2">
<p><b>Description</b></p>
</font></tH>
</tr>
<Tr>
<td ValigN="top">
<fonT SIZe="2">
<p><tt CLASs="monofont">Py_INCREF(</tt><i><TT CLass="monofont">obj</tT></I>
<TT class="monofont">)</tt></p>
</font></td>
<td valiGn="top">
<fOnt sIze="2">
<p>Increments the reference count of <i><Tt clASS="monofont">obj</Tt></i>
, which must be non-<tt CLASs="monofont">NULL</tt></p>
</FONT></td>
</tr>
<TR>
<TD valign="top">
<font size="2">
<p><tt claSs="monofont">Py_DECREF(</tT><i><tt Class="monofont">obj</Tt></i>
<tT CLAss="monofont">)</tt></P>
</FONt></td>
<tD VALign="top">
<fONT Size="2">
<p>Decrements the reference count of <i><tt class="monofont">obj</tt></i>
, which must be non-<tt claSs="monofont">NULL</tT></p>
</foNt></td>
</tR>
<tr>
<tD VALign="top">
<fONT Size="2">
<p><TT CLass="monofont">Py_XINCREF(</tT><I><TT class="monofont">obj</tt></i>
<tt class="monofont">)</tt></p>
</foNt></tD>
<td vAlign="top">
<Font SIZE="2">
<p>Increments the reference count of <i><tt CLASs="monofont">obj</tt></i>
, which may be <TT CLass="monofont">NULL</tT></P>
</FOnt></td>
</tr>
<tr>
<td valign="top">
<font SizE="2">
<p><tt Class="monofont">Py_XDECREF(</Tt><i><tT CLAss="monofont">obj</tt></I>
<TT Class="monofont">)</TT></P>
</Font></tD>
<TD Valign="top">
<font size="2">
<p>Decrements the reference count of <i><tt claSs="monofont">obj</tT></i>
, which may be <tt Class="monofont">NULL</Tt></p>
</fONT></Td>
</tr>
</cOLGRoup>
</tABLE></p>
<p>Manipulating the reference count of Python objects in C is a delicate topic, and readers are strongly advised to consult the 揈xtending and Embedding the Python Interpreter
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -