Variable Classification and Memory Organization


Variable Classification

  1. Package level variables - named in a declaration that is not in a procedure or function
    Example:
        package BigNumPkg is
        ...
        private
            Size : constant Positive := 50;
            type BigNum is array(0..Size-1) of Integer;
      

  2. Local variables - named in a declaration that is in a procedure or function, or in a declare block
  3. Example:
        with bignum; 
        procdure foo is
            b : bignumpkg.bignum;   -- Local
            begin
                ... 
                declare
                    f : Integer;    -- Local
                ... 
      

  4. Anonymous variables - NOT named in a declaration
    1. Access with a pointer
    2. Note that the pointer to the anonymous variable is itself frequently a local variable

Variable Allocation and Deallocation

    1. Package level variables are allocated/deallocated when the program begins/ends

    2. Local variables are allocated/deallocated each time the routine begins/ends execution following a stack protocol
      1. When the procedure is called, the locals are stacked and when it exits, they are popped
      2. Example:
        1. Procedures A, B, and C have locals X, Y, and Z, respectively.
        2. if A calls B which calls C, then C's locals are on top of the stack and A's locals are on the bottom of the stack

    3. Anonymous variables are allocated when explicitly created by the program and deallocated when explicitly destroyed by the program


Memory Organization


Java Example

class Foo{
void m(){
int l = 3;
Goo g = new Goo();
}
}

class Goo{
int x = 4;
int y = 5;
}

Physical Memory Organization