Static allocation: using declaration statements
- allocated before program begins execution( fortran,
C global variables)
Automatic allocation: using declaration statements - automatically allocated on entering scope- stack based storage management(Pascal local variables)
Dynamic allocation: using explicit directives -
may not be automatic - heap-based storage management
Storage management Approach
Explicit management by programmer:programmer must return unneeded memory to system like
C++ delete, object pascal dispose
Advantage: efficiency
Disadvantages:
Advantage: safety and convenience
disadvantage: relative inefficiency
Syntax for Automatic creation
In C++ and object Pascal (and sometimes in objective-C) memory for variables is often created using a simple declaration statement.
Card aCard; // C+ + declaration
var
aCard : Card;
{ object -pascal declaration }
Syntax for Dynamic creation
Always i smalltalk and sometimes in other languages, objects are created dynamically using the "new" operator.
d <== Card new.
aCard = new Card;
aCard = new Card(Card.spade,5);