Question

I am studying about the binding process and the classification of variable based on storage binding. So, I faced with four kind of variable:

  1. Static variables: these are bound to memory before execution (i.e., during compilation) and remain bound throughout execution.
  2. Stack-dynamic variables: these variables are statically bound to a type at compilation time, but they are not bound to a memory location until execution of the code reaches the declaration.
  3. Explicit heap-dynamic variables: these variables are allocated and deallocated via explicit run-time, programmer-specified instructions. The heap, not the stack, is used to provide the required memory cells.
  4. Implicit heap-dynamic variables: All the attributes for these variables, including memory cells, are bound when they are assigned a value.

My question is about the type 2 and 4. In programming languages whose the type biding is dynamic(Php, Ruby, Python, ...) all variable appears to be of type 4.

Is it true? All variables even the local variables are put on heap? Is this a implementation thing or there is not a possibility to implement a language with dynamic type binding whose local variables are put in stack and the others in heap?

Was it helpful?

Solution

No. There is no correlation between typing and allocation. The first is a language feature, the second (usually) a detail of a specific implementation that may depend on specific optimisations and other factors. Some variables will not be "allocated" at all. In more high-level languages, it is even wrong to assume that there is any connection between variables and allocation at all -- they just name certain values in the program text.

The only relation types have with all of this is that they enable more interesting optimisations, or at least make them much easier.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top