python preallocate some integers?

Discussion in 'Python' started by Dave Reed, Oct 19, 2004.

  1. Dave Reed

    Dave Reed Guest

    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
     
    Dave Reed, Oct 19, 2004
    #1
    1. Advertising

  2. Dave Reed <> wrote:

    > 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
     
    Alex Martelli, Oct 19, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jim

    preallocate list

    Jim, Apr 13, 2005, in forum: Python
    Replies:
    20
    Views:
    2,269
  2. Jan Danielsson
    Replies:
    3
    Views:
    327
  3. Replies:
    24
    Views:
    637
    Richard Bos
    Mar 2, 2009
  4. pointer

    integers to base, and some other questions

    pointer, Oct 30, 2009, in forum: C Programming
    Replies:
    7
    Views:
    291
    Barry Schwarz
    Oct 30, 2009
  5. Edek
    Replies:
    4
    Views:
    651
Loading...

Share This Page