<dd><emclass="refcount return_borrowed_ref">回傳值:借用參照。</em><emclass="stableabi"> 為 <aclass="reference internal" href="stable.html#stable"><spanclass="std std-ref">穩定 ABI 的一部分</span></a>.</em><p>Initialize a newly allocated object <em>op</em> with its type and initial
reference. Returns the initialized object. Other fields of the object are
not initialized. Despite its name, this function is unrelated to the
<p>In general, consider this function to be a low-level routine. Use
<aclass="reference internal" href="typeobj.html#c.PyTypeObject.tp_alloc" title="PyTypeObject.tp_alloc"><codeclass="xref c c-member docutils literal notranslate"><spanclass="pre">tp_alloc</span></code></a> where possible.
For implementing <codeclass="xref c c-member docutils literal notranslate"><spanclass="pre">tp_alloc</span></code> for your type, prefer
<aclass="reference internal" href="type.html#c.PyType_GenericAlloc" title="PyType_GenericAlloc"><codeclass="xref c c-func docutils literal notranslate"><spanclass="pre">PyType_GenericAlloc()</span></code></a> or <aclass="reference internal" href="#c.PyObject_New" title="PyObject_New"><codeclass="xref c c-func docutils literal notranslate"><spanclass="pre">PyObject_New()</span></code></a>.</p>
<divclass="admonition note">
<pclass="admonition-title">備註</p>
<p>This function only initializes the object's memory corresponding to the
initial <aclass="reference internal" href="structures.html#c.PyObject" title="PyObject"><codeclass="xref c c-type docutils literal notranslate"><spanclass="pre">PyObject</span></code></a> structure. It does not zero the rest.</p>
<p>When populating a type's <aclass="reference internal" href="typeobj.html#c.PyTypeObject.tp_alloc" title="PyTypeObject.tp_alloc"><codeclass="xref c c-member docutils literal notranslate"><spanclass="pre">tp_alloc</span></code></a> slot,
<aclass="reference internal" href="type.html#c.PyType_GenericAlloc" title="PyType_GenericAlloc"><codeclass="xref c c-func docutils literal notranslate"><spanclass="pre">PyType_GenericAlloc()</span></code></a> is preferred over a custom function that
<p>這不能用於有在 <aclass="reference internal" href="typeobj.html#c.PyTypeObject.tp_flags" title="PyTypeObject.tp_flags"><codeclass="xref c c-member docutils literal notranslate"><spanclass="pre">tp_flags</span></code></a> 中設定 <aclass="reference internal" href="typeobj.html#c.Py_TPFLAGS_HAVE_GC" title="Py_TPFLAGS_HAVE_GC"><codeclass="xref c c-macro docutils literal notranslate"><spanclass="pre">Py_TPFLAGS_HAVE_GC</span></code></a> 的物件;請改用 <aclass="reference internal" href="gcsupport.html#c.PyObject_GC_New" title="PyObject_GC_New"><codeclass="xref c c-macro docutils literal notranslate"><spanclass="pre">PyObject_GC_New</span></code></a>。</p>
<p>Memory allocated by this macro must be freed with <aclass="reference internal" href="memory.html#c.PyObject_Free" title="PyObject_Free"><codeclass="xref c c-func docutils literal notranslate"><spanclass="pre">PyObject_Free()</span></code></a>
(usually called via the object's <aclass="reference internal" href="typeobj.html#c.PyTypeObject.tp_free" title="PyTypeObject.tp_free"><codeclass="xref c c-member docutils literal notranslate"><spanclass="pre">tp_free</span></code></a> slot).</p>
<divclass="admonition note">
<pclass="admonition-title">備註</p>
<p>The returned memory is not guaranteed to have been completely zeroed
before it was initialized.</p>
</div>
<divclass="admonition note">
<pclass="admonition-title">備註</p>
<p>This macro does not construct a fully initialized object of the given
type; it merely allocates memory and prepares it for further
initialization by <aclass="reference internal" href="typeobj.html#c.PyTypeObject.tp_init" title="PyTypeObject.tp_init"><codeclass="xref c c-member docutils literal notranslate"><spanclass="pre">tp_init</span></code></a>. To construct a
fully initialized object, call <em>typeobj</em> instead. For example:</p>
<li><p>It allocates enough memory for the <em>TYPE</em> structure plus <em>size</em>
(<codeclass="docutils literal notranslate"><spanclass="pre">Py_ssize_t</span></code>) fields of the size given by the
<aclass="reference internal" href="typeobj.html#c.PyTypeObject.tp_itemsize" title="PyTypeObject.tp_itemsize"><codeclass="xref c c-member docutils literal notranslate"><spanclass="pre">tp_itemsize</span></code></a> field of <em>typeobj</em>.</p></li>
<p>When populating a type's <aclass="reference internal" href="typeobj.html#c.PyTypeObject.tp_alloc" title="PyTypeObject.tp_alloc"><codeclass="xref c c-member docutils literal notranslate"><spanclass="pre">tp_alloc</span></code></a> slot,
<aclass="reference internal" href="type.html#c.PyType_GenericAlloc" title="PyType_GenericAlloc"><codeclass="xref c c-func docutils literal notranslate"><spanclass="pre">PyType_GenericAlloc()</span></code></a> is preferred over a custom function that
simply calls this macro.</p>
<p>這不能用於有在 <aclass="reference internal" href="typeobj.html#c.PyTypeObject.tp_flags" title="PyTypeObject.tp_flags"><codeclass="xref c c-member docutils literal notranslate"><spanclass="pre">tp_flags</span></code></a> 中設定 <aclass="reference internal" href="typeobj.html#c.Py_TPFLAGS_HAVE_GC" title="Py_TPFLAGS_HAVE_GC"><codeclass="xref c c-macro docutils literal notranslate"><spanclass="pre">Py_TPFLAGS_HAVE_GC</span></code></a> 的物件;請改用 <aclass="reference internal" href="gcsupport.html#c.PyObject_GC_NewVar" title="PyObject_GC_NewVar"><codeclass="xref c c-macro docutils literal notranslate"><spanclass="pre">PyObject_GC_NewVar</span></code></a>。</p>
<p>Memory allocated by this function must be freed with <aclass="reference internal" href="memory.html#c.PyObject_Free" title="PyObject_Free"><codeclass="xref c c-func docutils literal notranslate"><spanclass="pre">PyObject_Free()</span></code></a>
(usually called via the object's <aclass="reference internal" href="typeobj.html#c.PyTypeObject.tp_free" title="PyTypeObject.tp_free"><codeclass="xref c c-member docutils literal notranslate"><spanclass="pre">tp_free</span></code></a> slot).</p>
<divclass="admonition note">
<pclass="admonition-title">備註</p>
<p>The returned memory is not guaranteed to have been completely zeroed
before it was initialized.</p>
</div>
<divclass="admonition note">
<pclass="admonition-title">備註</p>
<p>This macro does not construct a fully initialized object of the given
type; it merely allocates memory and prepares it for further
initialization by <aclass="reference internal" href="typeobj.html#c.PyTypeObject.tp_init" title="PyTypeObject.tp_init"><codeclass="xref c c-member docutils literal notranslate"><spanclass="pre">tp_init</span></code></a>. To construct a
fully initialized object, call <em>typeobj</em> instead. For example:</p>
<p><spanclass="versionmodified soft-deprecated"><aclass="reference internal" href="../glossary.html#term-soft-deprecated">Soft deprecated</a> since version 3.15.</span></p>
</div>
<p>These are aliases to existing functions and macros.
They exist solely for backwards compatibility.</p>