@@ -165,15 +165,17 @@ The following function sets, modeled after the ANSI C standard, but specifying
165165behavior when requesting zero bytes, are available for allocating and releasing
166166memory from the Python heap.
167167
168- The default memory block allocator uses the following functions:
169- :c:func: `malloc `, :c:func: `calloc `, :c:func: `realloc ` and :c:func: `free `; call
170- ``malloc(1) `` (or ``calloc(1, 1) ``) when requesting zero bytes.
168+ By default, these functions use :ref: `pymalloc memory allocator <pymalloc >`.
171169
172170.. warning ::
173171
174172 The :term: `GIL <global interpreter lock> ` must be held when using these
175173 functions.
176174
175+ .. versionchanged :: 3.6
176+
177+ The default allocator is now pymalloc instead of system :c:func: `malloc `.
178+
177179.. c :function :: void * PyMem_Malloc (size_t n)
178180
179181 Allocates *n* bytes and returns a pointer of type :c:type:`void\*` to the
@@ -295,15 +297,32 @@ Customize Memory Allocators
295297
296298 Enum used to identify an allocator domain. Domains:
297299
298- * :c:data: `PYMEM_DOMAIN_RAW `: functions :c:func: `PyMem_RawMalloc `,
299- :c:func: `PyMem_RawRealloc `, :c:func: `PyMem_RawCalloc ` and
300- :c:func: `PyMem_RawFree `
301- * :c:data: `PYMEM_DOMAIN_MEM `: functions :c:func: `PyMem_Malloc `,
302- :c:func: `PyMem_Realloc `, :c:func: `PyMem_Calloc ` and :c:func: `PyMem_Free `
303- * :c:data: `PYMEM_DOMAIN_OBJ `: functions :c:func: `PyObject_Malloc `,
304- :c:func: `PyObject_Realloc `, :c:func: `PyObject_Calloc ` and
305- :c:func: `PyObject_Free `
300+ .. c :var :: PYMEM_DOMAIN_RAW
301+
302+ Functions:
303+
304+ * :c:func: `PyMem_RawMalloc `
305+ * :c:func: `PyMem_RawRealloc `
306+ * :c:func: `PyMem_RawCalloc `
307+ * :c:func: `PyMem_RawFree `
308+
309+ .. c :var :: PYMEM_DOMAIN_MEM
306310
311+ Functions:
312+
313+ * :c:func: `PyMem_Malloc `,
314+ * :c:func: `PyMem_Realloc `
315+ * :c:func: `PyMem_Calloc `
316+ * :c:func: `PyMem_Free `
317+
318+ .. c :var :: PYMEM_DOMAIN_OBJ
319+
320+ Functions:
321+
322+ * :c:func: `PyObject_Malloc `
323+ * :c:func: `PyObject_Realloc `
324+ * :c:func: `PyObject_Calloc `
325+ * :c:func: `PyObject_Free `
307326
308327.. c :function :: void PyMem_GetAllocator (PyMemAllocatorDomain domain, PyMemAllocatorEx *allocator)
309328
@@ -328,18 +347,12 @@ Customize Memory Allocators
328347
329348.. c:function:: void PyMem_SetupDebugHooks(void)
330349
331- Setup hooks to detect bugs in the following Python memory allocator
332- functions:
333-
334- - :c:func:`PyMem_RawMalloc`, :c:func:`PyMem_RawRealloc`,
335- :c:func:`PyMem_RawCalloc`, :c:func:`PyMem_RawFree`
336- - :c:func:`PyMem_Malloc`, :c:func:`PyMem_Realloc`, :c:func:`PyMem_Calloc`,
337- :c:func:`PyMem_Free`
338- - :c:func:`PyObject_Malloc`, :c:func:`PyObject_Realloc`,
339- :c:func:`PyObject_Calloc`, :c:func:`PyObject_Free`
350+ Setup hooks to detect bugs in the Python memory allocator functions.
340351
341352 Newly allocated memory is filled with the byte ``0xCB``, freed memory is
342- filled with the byte ``0xDB``. Additional checks:
353+ filled with the byte ``0xDB``.
354+
355+ Runtime checks:
343356
344357 - Detect API violations, ex: :c:func:`PyObject_Free` called on a buffer
345358 allocated by :c:func:`PyMem_Malloc`
@@ -377,8 +390,9 @@ to 512 bytes) with a short lifetime. It uses memory mappings called "arenas"
377390with a fixed size of 256 KB. It falls back to :c:func:`PyMem_RawMalloc` and
378391:c:func:`PyMem_RawRealloc` for allocations larger than 512 bytes.
379392
380- *pymalloc* is the default allocator of the :c:data:`PYMEM_DOMAIN_OBJ` domain
381- (ex: :c:func: `PyObject_Malloc `).
393+ *pymalloc* is the default allocator of the :c:data:`PYMEM_DOMAIN_MEM` (ex:
394+ :c:func: `PyObject_Malloc `) and :c:data:`PYMEM_DOMAIN_OBJ` (ex:
395+ :c:func: `PyObject_Malloc `) domains.
382396
383397The arena allocator uses the following functions:
384398
0 commit comments