- Static memory allocation
Static memory allocation refers to the process of allocating memory at compile-time before the associated program is executed, unlike
dynamic memory allocation orautomatic memory allocation where memory is allocated as required at run-time.An application of this technique involves a program module (e.g. function or
subroutine ) declaring static data locally, such that these data are inaccessible in other modules unless references to it are passed as parameters or returned. A single copy of static data is retained and accessible through many calls to the function in which it is declared. Static memory allocation therefore has the advantage of modularising data within a program design in the situation where these data must be retained through the runtime of the program.The use of static variables within a class in
object oriented programming enables a single copy of such data to be shared between all the objects of that class.Object constants known at compile-time, like
string literal s, are usually allocated statically. In object-oriented programming, thevirtual method table s of classes are usually allocated statically. A statically defined value can also be global in its scope ensuring the sameimmutable value is used throughout a run for consistency.ee also
Global variable
Wikimedia Foundation. 2010.