Mengalokasikan objek kedalam struktur data (heap)

PyObject *_PyObject_New(PyTypeObject *type)
Return value: New reference.
PyVarObject *_PyObject_NewVar(PyTypeObject *type, Py_ssize_t size)
Return value: New reference.
PyObject *PyObject_Init(PyObject *op, PyTypeObject *type)
Return value: Borrowed reference. Part of the Stable ABI.

Initialize a newly allocated object op with its type and initial reference. Returns the initialized object. If type indicates that the object participates in the cyclic garbage detector, it is added to the detector's set of observed objects. Other fields of the object are not affected.

PyVarObject *PyObject_InitVar(PyVarObject *op, PyTypeObject *type, Py_ssize_t size)
Return value: Borrowed reference. Part of the Stable ABI.

Ini melakukan segalanya PyObject_Init(), dan juga menginisialiasi panjang informasi pada sebuah ukuran object variabel.

TYPE *PyObject_New(TYPE, PyTypeObject *type)
Return value: New reference.

Allocate a new Python object using the C structure type TYPE and the Python type object type. Fields not defined by the Python object header are not initialized. The caller will own the only reference to the object (i.e. its reference count will be one). The size of the memory allocation is determined from the tp_basicsize field of the type object.

TYPE *PyObject_NewVar(TYPE, PyTypeObject *type, Py_ssize_t size)
Return value: New reference.

Alokasikan objek Python baru menggunakan tipe TYPE struktur C dan objek tipe Python type. Fields yang tidak ditentukan oleh header objek Python tidak diinisialisasi. Memori yang dialokasikan memungkinkan untuk struktur TYPE ditambah size fields dari ukuran yang diberikan oleh field tp_itemsize dari tipe. Ini berguna untuk mengimplementasikan objek seperti tuple, yang dapat menentukan ukurannya pada waktu pembentukan construction. Menanamkan array dari fields ke dalam alokasi yang sama mengurangi jumlah alokasi, meningkatkan efisiensi manajemen memori.

void PyObject_Del(void *op)

Merilis memori yang dialokasikan ke objek menggunakan PyObject_New() atau PyObject_NewVar(). Ini biasanya dipanggil dari penangan tp_dealloc yang ditentukan dalam tipe objek. fields dari objek tidak boleh diakses setelah panggilan ini karena memori tidak lagi menjadi objek Python yang valid.

PyObject _Py_NoneStruct

Object yang terlihat di Python sebagai None. Ini seharusnya hanya dapat diakses menggunakan makro Py_None, yang mengevaluasi ke sebuah pointer ke object ini.

Lihat juga

PyModule_Create()

Untuk mengalokasikan dan membuat modul ekstensi.