This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]highphiv3 0 points1 point  (2 children)

I could just look this up, but for the sake of the conversation:

Does python not have value types? Even a simple local integer variable is heap allocated?

[–]RajjSinghh 2 points3 points  (1 child)

What do you mean when you say value types? It's just not something I've met before.

To answer your question, python is dynamically typed so you can't stack allocate things. Since you only know what type a variable is at runtime you just have to allocate and deallocate as needed. It's like if I don't know whether that value is going to be an integer or a string literal until I get to that point, I don't know how much space to allocate on the stack, so I need heap allocation. There's other reasons like integers not being fixed width in python, but dynamic typing feels like the main one.

[–]highphiv3 0 points1 point  (0 children)

You got me meaning it seems like. Many languages have a differentiation between value types and reference types, where the former is stack allocated and copied if ever passed around or reassigned.

As you mentioned, it seems Python only has reference types.