does python stores similar objects at contiguous memory locations? -


does python stores similar objects @ memory locations nearer each other? because id of similar objects, lists , tuples, nearer each other object of type str.

no, except of course coincidence. while highly implementation- , environment-specific, , there memory management schemes dedicate page-sized memory regions objects of same type, no python implementations i'm aware of exhibits behavior describe. possible exception of small numbers, cached under hood , located next each other.

what you're seeing may because string literals created @ import time (part of constants in byte code) , interned, while lists , tuples (that don't contain literals) created while running code. if bunch of memory allocated in between (especially if isn't freed), state of heap may sufficiently different quite different addresses handed out when you're checking.


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -