SLIDE 1
6.172 — Performance Engineering of Software Systems Spring 2009
Lecture 9
MIT OpenCourseWare
Dynamic Storage Allocation
Stack allocation: LIFO (last-in-first-out)
Array and pointer
- A
used Pbefore Pafter unused
Figure 1: A diagram of the stack (Image by MIT OpenCourseWare.) Allocate x bytes: q = p; p += x; return q; O(1) time Few operations and good cache behavior (temporal and spatial) Free: p = q; O(1) time Issues: Inline (especially for small allocations)
- May want to round up to word (or cache block) boundary
- Must free consistent with stack discipline ⇒ limited applicability, but fast when it works.