Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Hmm, assuming you’re talking about heap allocation, could you elaborate? I’m curious.

[Edit: You may have meant “when simple integer addition [in a scripting language] can take more time than allocation in a compiled language”, in which case sure, I agree. I had originally interpreted your statement as saying compiled languages can do allocation faster than they can do addition…]

Allocation in most environments I’ve seen involves keeping track of a “free list”, which does some amount of pointer chasing to find a contiguous section of memory that can fulfill the request. Deallocation drops the item from the list, etc. This can result in some fragmentation, and the segments of memory managed by the free list are less likely to be in cache because they’re somewhat dispersed compared to stack memory. Some environments have multiple free lists depending on the expected size of the allocated objects, to avoid fragmentation.

How could all this be faster than a single integer addition?



When it's a bigint addition, as all integer additions in Python are.

Also, even when both integers are small, Python usually has to do an allocation anyway to store the result.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: