Geraldo Xexeo <gxe...@gmail.com> added the comment:

"So 2**8 is a magic number, for whatever reason."

Actually, this is true. Accordingly to 
https://rushter.com/blog/python-integer-implementation/

"Optimization of commonly-used integers
Small integer objects in a range of -5 to 256 are always pre-allocated during 
initialization. Because Python integers are immutable, we can use them as 
singletons. Every time you need to create small integer instead of creating new 
object Python just points to already allocated one. Thereby it saves a lot of 
space and computation for commonly-used integers.

Interestingly enough, the PyLongObject structure takes at least 28 bytes for 
every allocated integer and therefore takes three times as much memory as a 
simple 64-bit C integer."

This are constants 

#define NSMALLPOSINTS           257
#define NSMALLNEGINTS           5

You can find the code in:

https://github.com/python/cpython/blob/master/Objects/longobject.c

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue36592>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to