|
|
Typical restrictions:
There are no markers in the memory to denotate where the address item are located and how big they are (how many bytes are used to hold the value of the item - short: 2 bytes, int 4 bytes, etc) !!!
The compiler will find an unused portion of consecute memory bytes to store the variable.
In addition, the starting location (= address) of the allocated memory and the size (number of bytes) are remembered by the compiler.
Schematically:
in its symbol table variable
(Remember, the compiler is a program and a program can have variables... The symbol table is one of the many variables used to write a compiler...)
|
|
public class ExampleClass { static int x; // Keyword static defines a Class variable int y; // Absent of static defines an Instance var public int Method1( int a ) // a is a parameter variable { int b; // Local variables are defined inside a method .... } } |
|
|
|
|
|
|
The following figures shows how variables types of variables and the program instructions are stored in memory when a program is executed:
The program instructions and static variables will continue to occupy the memory for as long as the program is executing !
This portion of memory is used to "allocate space" for new variables
When a new variable is "created" (a misnomer, humans nor computers can create anything...), some free/unoccupied memory will be marked as "used".
(I quote "created" because what actually happens is: memory space immediately following the static variable will be marked as used - there is no real creation going on like that as documented in Genesis 1:1 of the Bible)
|
Later in the course, I will explain why a stack is used when I discuss subroute call and return ( click here )....