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.
Berubah pada versi 2.5: This function used an
int
type for size. This might require changes in your code for properly supporting 64-bit systems.
-
PyObject*
PyObject_Init
(PyObject *op, PyTypeObject *type)¶ - Return value: Borrowed reference.
Inisialisasi sebuah objek yang baru dialokasi op dengan tipe dan referensi awal. Mengembalikan objek yang telah diinisialisasi. Jika tipe pada objek mengindikasi bahwa objek berpartisipasi di dalam siklus detektor sampah, maka objek tersebut ditambahkan pada set detektor terhadap objek sedang diobservasi.
-
PyVarObject*
PyObject_InitVar
(PyVarObject *op, PyTypeObject *type, Py_ssize_t size)¶ - Return value: Borrowed reference.
Ini melakukan segalanya
PyObject_Init()
, dan juga menginisialiasi panjang informasi pada sebuah ukuran object variabel.Berubah pada versi 2.5: This function used an
int
type for size. This might require changes in your code for properly supporting 64-bit systems.
-
TYPE*
PyObject_New
(TYPE, PyTypeObject *type)¶ - 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; jumlah referensi objek akan menjadi satu. Ukuran alokasi memori ditentukan dari field
tp_basicsize
pada objek tipe.
-
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.Berubah pada versi 2.5: This function used an
int
type for size. This might require changes in your code for properly supporting 64-bit systems.
-
void
PyObject_Del
(PyObject *op)¶ Merilis memori yang dialokasikan ke objek menggunakan
PyObject_New()
atauPyObject_NewVar()
. Ini biasanya dipanggil dari penangantp_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_InitModule
(char *name, PyMethodDef *methods)¶ - Return value: Borrowed reference.
Create a new module object based on a name and table of functions, returning the new module object.
Berubah pada versi 2.3: Older versions of Python did not support NULL as the value for the methods argument.
-
PyObject*
Py_InitModule3
(char *name, PyMethodDef *methods, char *doc)¶ - Return value: Borrowed reference.
Create a new module object based on a name and table of functions, returning the new module object. If doc is non-NULL, it will be used to define the docstring for the module.
Berubah pada versi 2.3: Older versions of Python did not support NULL as the value for the methods argument.
-
PyObject*
Py_InitModule4
(char *name, PyMethodDef *methods, char *doc, PyObject *self, int apiver)¶ - Return value: Borrowed reference.
Create a new module object based on a name and table of functions, returning the new module object. If doc is non-NULL, it will be used to define the docstring for the module. If self is non-NULL, it will be passed to the functions of the module as their (otherwise NULL) first parameter. (This was added as an experimental feature, and there are no known uses in the current version of Python.) For apiver, the only value which should be passed is defined by the constant
PYTHON_API_VERSION
.Catatan
Most uses of this function should probably be using the
Py_InitModule3()
instead; only use this if you are sure you need it.Berubah pada versi 2.3: Older versions of Python did not support NULL as the value for the methods argument.