@@ -499,12 +499,6 @@ Legend:
499499 :option: `--with-memory-sanitizer ` option.
500500
501501
502- .. _custom-raw-allocator :
503-
504- .. _custom-mem-allocator :
505-
506- .. _custom-object-allocator :
507-
508502.. _customize-memory-allocators :
509503
510504Customize Memory Allocators
@@ -539,6 +533,50 @@ to identify where allocations happen. Typically, the wrapped allocator
539533is stored in (or within) the ``PyMemAllocatorEx.ctx`` field
540534of the wrapper.
541535
536+ Regardless of the kind, the following applies to every custom
537+ allocator, depending on the domain:
538+
539+ .. _custom-raw-allocator:
540+
541+ Raw domain:
542+
543+ * a system allocator (or wrapper around one)
544+ * the memory is requested directly from the system
545+ * independent of the Python runtime
546+ * not associated with any interpreter
547+ * may be used before the runtime is initialized and after it's finalized
548+ * may be used with the runtime in an unknown state
549+ * must be thread-safe
550+ * must work whether or not the :term:`GIL` is held
551+
552+ .. _custom-mem-allocator:
553+
554+ "Mem" domain:
555+
556+ * may use a Python-specific heap
557+ * allocated memory will be used only in a single interpreter
558+ * memory for each interpreter is likely kept separate
559+ * must be thread-safe
560+ * always called with the runtime in an active, stable state
561+ * always called with the target interpreter/tstate set in the current thread
562+ (:c:func: `PyInterpreterState_Get `, :c:func: `PyThreadState_Get `)
563+ * always called with the current interpreter's :term:`GIL` held
564+ * never used for memory belonging to Python objects
565+
566+ .. _custom-object-allocator:
567+
568+ Object domain:
569+
570+ * will use a Python-specific heap
571+ * allocated memory will be used only in a single interpreter
572+ * memory for each interpreter is kept separate
573+ * must be thread-safe
574+ * always called with the runtime in an active, stable state
575+ * always called with the target interpreter/tstate set in the current thread
576+ (:c:func: `PyInterpreterState_Get `, :c:func: `PyThreadState_Get `)
577+ * always called with the current interpreter's :term:`GIL` held
578+ * only used for memory belonging to Python objects
579+
542580.. versionadded:: 3.4
543581
544582.. c:type:: PyMemAllocatorEx
0 commit comments