[accepted revision] | [accepted revision] |
Content deleted Content added
Not just the heap. Tags: Reverted Mobile edit Mobile app edit iOS app edit App section source |
Undid revision 1307694532 by Elrondil (talk) - alloca is not in any standard and does not allow one to allocate blocks of memory of arbitrary size |
||
Line 496:
* [[Static memory allocation]]: space for the object is provided in the binary at compile-time; these objects have an [[Variable (programming)#Scope and extent|extent]] (or lifetime) as long as the binary which contains them is loaded into memory.
* [[Automatic memory allocation]]: temporary objects can be stored on the [[Call stack|stack]], and this space is automatically freed and reusable after the block in which they are declared is exited.
* [[C dynamic memory allocation|Dynamic memory allocation]]: blocks of memory of arbitrary size can be requested at run-time using library functions such as <code>malloc</code> from a region of memory called the [[Memory management|heap]];
These three approaches are appropriate in different situations and have various trade-offs. For example, static memory allocation has little allocation overhead, automatic allocation may involve slightly more overhead, and dynamic memory allocation can potentially have a great deal of overhead for both allocation and deallocation. The persistent nature of static objects is useful for maintaining state information across function calls, automatic allocation is easy to use but stack space is typically much more limited and transient than either static memory or heap space, and dynamic memory allocation allows convenient allocation of objects whose size is known only at run-time. Most C programs make extensive use of all three.
|