Please enable JavaScript.
Coggle requires JavaScript to display documents.
Variables - Coggle Diagram
Variables
a collection of properties
Type (Range of possible values)
restriction on the values it can hold and the operations that can be applied on it
e.g. int, float, double
Scope (Where in the program it can be accessed)
lifetime in the program
types
static scoping
advantages
readability
locality of reasoning
less run time overhead
disadvantages
some loss of flexibility
dynamic scoping
advantages
extra convenience
disadvantages
loss of readability
run-time overhead
Address (Memory location)
may have different addresses
at different times during execution
at different places in a program
Aliasing
Unions
user-defined data type
allows storing different types of data in the same memory location
two variables referring to the same memory location
Name or identifier
label given to identify a memory space
name types
simple names
composite names
In compiled languages
names only exists at compile time
at runtime only values and their memory addresses exist
In interpreted languages
names and values coexist during run-time
design issues
Maximum length of a name
Case sensitivity
Keywords or reserved words
characters can be used and the concatenated
name spaces
context for identifiers
names cannot have more than one meaning
names with different meanings cannot share the same name
enable identifier names to be logically grouped
Lifetime
period of time a variable is bound to a memory location
types based on their life-times
Static
only one copy for the entire class
remain bound to the cell until the program terminates
advantages
efficiency
no runtime overhead
history sensitive
disadvantages
no recursion possible
storage cannot be shared among variables
Stack-dynamic (Automatic)
advantages
allow recursions
conserve storage
disadvantages
memory allocation and deallocation overhead.
not history sensitive
memory is allocated when a function is called
memory is deallocated when a function returns
variables are stored in stack
Explicit heap-dynamic
allocated and deallocated by explicit run time instructions
variables are accessed only through pointers or reference variables
variables resides in the heap
memory remains allocated until explicitly deallocate
Implicit heap-dynamic
acquire types only when assigned values at runtime
allocation and deallocation are handled by the runtime system or garbage collector
Value (Particular value at a moment)
lValue
address of the variable
Actual Value (Primitive Types)
these values are directly stored in the variable
Reference Value (Aggregation Types)
the variable holds a memory address or reference that points to the actual object or array stored elsewhere in memory.
rvalue
value of the variable
Dereferencing
process of accessing the value stored in the memory location
Binding
process of establishing an association
Binding time
Language design time
Language implementation time
Compile time
Load time
Runtime
static binding
occurs before run time
remains unchanged throughout program execution
dynamic binding
occurs during execution
change during execution of the program
Storage binding
binding memory cells to a variable
allocation
deallocation
main areas
global or static area
stack
heap
provide names for the storage chunks
transfer data from one part of the program to the other
A named space of the memory