0

Python int obj has dynamic memory allocation. When the number is small, memory is small; when large, otherwise. But the numpy array unit has fixed memory once declared.

I am very curious about how python implemented these mechanisms in its source code, either in C++ or Python code.

Where can I get a valid version of python source code to have a look? And, how to find the answer to a question, like above?

pphero0287
  • 47
  • 1
  • 8
  • If you make a NumPy array from data - there's no issue to allocate a buffer big enough to fit the data. When you try to expand the array and it doesn't fit the buffer - just allocate a buffer that is bigger than previous. What's curious in that? – Alexey S. Larionov Jun 17 '21 at 10:00
  • Have you tried a common search engine? The one I'm using, when fed with the words "source code of python", returns https://www.python.org/downloads/source/ which looks pretty authoritative. – Hans-Martin Mosner Jun 17 '21 at 10:00
  • Does this answer your question? [Finding the source code for built-in Python functions?](https://stackoverflow.com/questions/8608587/finding-the-source-code-for-built-in-python-functions) – Gino Mempin Jun 17 '21 at 10:36
  • @Hans the source code looks good but I can not locate where the class 'int' is implemented. – pphero0287 Jun 17 '21 at 11:21

1 Answers1

0

CPython source is available via github.com/python, for discussion of implementation (rather than code only) see laurentluce.com post.

Daweo
  • 31,313
  • 3
  • 12
  • 25