Skip to main content

Overview

Python provides specialized memory allocators for different purposes:
  1. Raw - System allocator wrappers (no GIL required)
  2. Mem - Python heap (GIL required)
  3. Object - Python objects only

Memory Domains

Raw Memory

For buffers, no GIL required.

Python Memory

For Python-managed memory.

Object Memory

Free-threaded builds: Only use PyObject_* for Python objects, not buffers!

Memory Errors

Set MemoryError exception. Example:

Best Practices

Never mix allocators:

See Also