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
Post a Comment