힙에 객체 할당하기¶
-
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.
새로 할당된 객체 op를 형과 초기 참조로 초기화합니다. 초기화된 객체를 반환합니다. 객체의 다른 필드는 영향을 받지 않습니다.
-
PyVarObject *PyObject_InitVar(PyVarObject *op, PyTypeObject *type, Py_ssize_t size)¶
- Return value: Borrowed reference. Part of the Stable ABI.
이것은
PyObject_Init()
가 수행하는 모든 작업을 수행하고, 가변 크기 객체의 길이 정보도 초기화합니다.
-
PyObject_New(TYPE, typeobj)¶
C 구조체 형 TYPE과 파이썬 형 객체 typeobj (
PyTypeObject*
) 를 사용하여 새로운 파이썬 객체를 할당합니다. 파이썬 객체 헤더로 정의되지 않은 필드는 초기화되지 않습니다. 호출자는 객체에 대한 유일한 참조를 소유하게 됩니다 (즉, 객체의 참조 횟수는 1이 됩니다). 메모리 할당의 크기는 형 객체의tp_basicsize
필드에서 결정됩니다.Note that this function is unsuitable if typeobj has
Py_TPFLAGS_HAVE_GC
set. For such objects, usePyObject_GC_New()
instead.
-
PyObject_NewVar(TYPE, typeobj, size)¶
C 구조체 형 TYPE과 파이썬 타입 형 typeobj (
PyTypeObject*
) 를 사용하여 새로운 파이썬 객체를 할당합니다. 파이썬 객체 헤더로 정의되지 않은 필드는 초기화되지 않습니다. 할당된 메모리는 TYPE 구조체에 더해 typeobj의tp_itemsize
필드에 의해 주어진 크기의 size (Py_ssize_t
) 필드를 허용합니다. 이는 튜플과 같은 객체를 구현할 때 유용합니다. 튜플은 만들 때 크기를 결정할 수 있습니다. 같은 할당에 필드 배열을 포함 시키면, 할당 횟수가 줄어들어, 메모리 관리 효율성이 향상됩니다.Note that this function is unsuitable if typeobj has
Py_TPFLAGS_HAVE_GC
set. For such objects, usePyObject_GC_NewVar()
instead.
-
void PyObject_Del(void *op)¶
Same as
PyObject_Free()
.
더 보기
PyModule_Create()
확장 모듈을 할당하고 만듭니다.