@@ -92,8 +92,8 @@ functions are thread-safe, the :term:`GIL <global interpreter lock>` does not
9292need to be held.
9393
9494The default raw memory block allocator uses the following functions:
95- :c:func: `malloc `, :c:func: `realloc ` and :c:func: `free `; call `` malloc(1) `` when
96- requesting zero bytes.
95+ :c:func: `malloc `, :c:func: `calloc `, :c:func: ` realloc ` and :c:func: `free `; call
96+ `` malloc(1) `` (or `` calloc(1, 1) ``) when requesting zero bytes.
9797
9898.. versionadded :: 3.4
9999
@@ -106,6 +106,17 @@ requesting zero bytes.
106106 been initialized in any way.
107107
108108
109+ .. c:function:: void* PyMem_RawCalloc(size_t nelem, size_t elsize)
110+
111+ Allocates *nelem* elements each whose size in bytes is *elsize* and returns
112+ a pointer of type :c:type:`void\*` to the allocated memory, or *NULL* if the
113+ request fails. The memory is initialized to zeros. Requesting zero elements
114+ or elements of size zero bytes returns a distinct non-*NULL* pointer if
115+ possible, as if ``PyMem_RawCalloc(1, 1)`` had been called instead.
116+
117+ .. versionadded:: 3.5
118+
119+
109120.. c:function:: void* PyMem_RawRealloc(void *p, size_t n)
110121
111122 Resizes the memory block pointed to by *p * to *n * bytes. The contents will
@@ -136,8 +147,8 @@ behavior when requesting zero bytes, are available for allocating and releasing
136147memory from the Python heap.
137148
138149The default memory block allocator uses the following functions:
139- :c:func: `malloc `, :c:func: `realloc ` and :c:func: `free `; call `` malloc(1) `` when
140- requesting zero bytes.
150+ :c:func: `malloc `, :c:func: `calloc `, :c:func: ` realloc ` and :c:func: `free `; call
151+ `` malloc(1) `` (or `` calloc(1, 1) ``) when requesting zero bytes.
141152
142153.. warning::
143154
@@ -152,6 +163,17 @@ requesting zero bytes.
152163 been called instead. The memory will not have been initialized in any way.
153164
154165
166+ .. c:function:: void* PyMem_Calloc(size_t nelem, size_t elsize)
167+
168+ Allocates *nelem* elements each whose size in bytes is *elsize* and returns
169+ a pointer of type :c:type:`void\*` to the allocated memory, or *NULL* if the
170+ request fails. The memory is initialized to zeros. Requesting zero elements
171+ or elements of size zero bytes returns a distinct non-*NULL* pointer if
172+ possible, as if ``PyMem_Calloc(1, 1)`` had been called instead.
173+
174+ .. versionadded:: 3.5
175+
176+
155177.. c:function:: void* PyMem_Realloc(void *p, size_t n)
156178
157179 Resizes the memory block pointed to by *p * to *n * bytes. The contents will be
@@ -222,11 +244,17 @@ Customize Memory Allocators
222244 +----------------------------------------------------------+---------------------------------------+
223245 | ``void* malloc(void *ctx, size_t size) `` | allocate a memory block |
224246 +----------------------------------------------------------+---------------------------------------+
247+ | ``void* calloc(void *ctx, size_t nelem, size_t elsize) `` | allocate a memory block initialized |
248+ | | with zeros |
249+ +----------------------------------------------------------+---------------------------------------+
225250 | ``void* realloc(void *ctx, void *ptr, size_t new_size) `` | allocate or resize a memory block |
226251 +----------------------------------------------------------+---------------------------------------+
227252 | ``void free(void *ctx, void *ptr) `` | free a memory block |
228253 +----------------------------------------------------------+---------------------------------------+
229254
255+ .. versionchanged :: 3.5
256+ Add a new field ``calloc ``.
257+
230258.. c :type :: PyMemAllocatorDomain
231259
232260 Enum used to identify an allocator domain. Domains:
0 commit comments