Skip to content

Commit fde5785

Browse files
Enumerate characteristics for custom allocators.
1 parent 44074db commit fde5785

1 file changed

Lines changed: 44 additions & 6 deletions

File tree

‎Doc/c-api/memory.rst‎

Lines changed: 44 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -437,12 +437,6 @@ Legend:
437437
* "Debug build": :ref:`Python build in debug mode <debug-build>`.
438438
439439
440-
.. _custom-raw-allocator:
441-
442-
.. _custom-mem-allocator:
443-
444-
.. _custom-object-allocator:
445-
446440
.. _customize-memory-allocators:
447441
448442
Customize Memory Allocators
@@ -477,6 +471,50 @@ to identify where allocations happen. Typically, the wrapped allocator
477471
is stored in (or within) the ``PyMemAllocatorEx.ctx`` field
478472
of the wrapper.
479473
474+
Regardless of the kind, the following applies to every custom
475+
allocator, depending on the domain:
476+
477+
.. _custom-raw-allocator:
478+
479+
Raw domain:
480+
481+
* a system allocator (or wrapper around one)
482+
* the memory is requested directly from the system
483+
* independent of the Python runtime
484+
* not associated with any interpreter
485+
* may be used before the runtime is initialized and after it's finalized
486+
* may be used with the runtime in an unknown state
487+
* must be thread-safe
488+
* must work whether or not the :term:`GIL` is held
489+
490+
.. _custom-mem-allocator:
491+
492+
"Mem" domain:
493+
494+
* may use a Python-specific heap
495+
* allocated memory will be used only in a single interpreter
496+
* memory for each interpreter is likely kept separate
497+
* must be thread-safe
498+
* always called with the runtime in an active, stable state
499+
* always called with the target interpreter/tstate set in the current thread
500+
(:c:func:`PyInterpreterState_Get`, :c:func:`PyThreadState_Get`)
501+
* always called with the current interpreter's :term:`GIL` held
502+
* never used for memory belonging to Python objects
503+
504+
.. _custom-object-allocator:
505+
506+
Object domain:
507+
508+
* will use a Python-specific heap
509+
* allocated memory will be used only in a single interpreter
510+
* memory for each interpreter is kept separate
511+
* must be thread-safe
512+
* always called with the runtime in an active, stable state
513+
* always called with the target interpreter/tstate set in the current thread
514+
(:c:func:`PyInterpreterState_Get`, :c:func:`PyThreadState_Get`)
515+
* always called with the current interpreter's :term:`GIL` held
516+
* only used for memory belonging to Python objects
517+
480518
.. versionadded:: 3.4
481519
482520
.. c:type:: PyMemAllocatorEx

0 commit comments

Comments
 (0)