As per this discussion, PyMem_Malloc() requires the GIL; however, if the function is nothing more than an alias for malloc(), who cares?
Asked
Active
Viewed 527 times
7
Community
- 1
- 1
Noob Saibot
- 4,573
- 10
- 36
- 60
1 Answers
5
Because it is sometimes more than simply an alias for malloc(). Sometimes it is an alias for _PyMem_DebugMalloc() and there is some global accounting there to keep track of unique memory objects. There's no real point in releasing the GIL just for a PyMem_Malloc() call, so you're probably doing something more complicated in C. If that's the case, you can simply call malloc() and not get any of the debugging stuff.
Nathan Binkert
- 8,744
- 1
- 29
- 37
-
1As of Python 3.4, there's also `PyMem_RawMalloc()` which doesn't require the GIL to be held (see [PEP 445](https://www.python.org/dev/peps/pep-0445/)). – Kai Jul 03 '17 at 08:03