python preallocate some integers?

D

Dave Reed

I seem to recall somewhere, possibly in the Python Essential Reference
(but unfortunately, books don't have a "find" function), that Python
preallocates and never destroys the first 100 integers. A minute of
google searching didn't help me so I tried some simple tests. Based on
these, it appears that only one copy of the integers -5 through 99 is
created.

Can someone please verify this for me or tell me what is done with
regard to this?

Thanks,
Dave
 
A

Alex Martelli

Dave Reed said:
I seem to recall somewhere, possibly in the Python Essential Reference
(but unfortunately, books don't have a "find" function), that Python
preallocates and never destroys the first 100 integers. A minute of
google searching didn't help me so I tried some simple tests. Based on
these, it appears that only one copy of the integers -5 through 99 is
created.

Can someone please verify this for me or tell me what is done with
regard to this?

In the current implementation, that is indeed the case. Of course,
since it's strictly an optimization issue, that's a detail which could
change even between one subrelease and the next, so make sure your
application doesn't depend on it.


Alex
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top