University ¡of ¡Washington ¡
Today ¡
¢ Dynamic ¡memory ¡alloca7on ¡
§ Size ¡of ¡data ¡structures ¡may ¡only ¡be ¡known ¡at ¡run ¡6me ¡ § Need ¡to ¡allocate ¡space ¡on ¡the ¡heap ¡ § Need ¡to ¡de-‑allocate ¡(free) ¡unused ¡memory ¡so ¡it ¡can ¡be ¡re-‑allocated ¡
¢ Implementa7on ¡ ¡
§ Implicit ¡free ¡lists ¡ § Explicit ¡free ¡lists ¡– ¡subject ¡of ¡next ¡programming ¡assignment ¡ § Segregated ¡free ¡lists ¡
¢ Garbage ¡collec7on ¡ ¢ Common ¡memory-‑related ¡bugs ¡in ¡C ¡programs ¡
Autumn ¡2012 ¡ 1 ¡ Memory ¡Alloca7on ¡
University ¡of ¡Washington ¡
Process ¡Memory ¡Image ¡
kernel ¡virtual ¡memory ¡ run-‑7me ¡heap ¡ program ¡text ¡(.text) ¡ ini7alized ¡data ¡(.data) ¡ unini7alized ¡data ¡(.bss) ¡ stack ¡ 0 ¡
%esp
memory ¡protected ¡ from ¡user ¡code ¡
2 ¡
What ¡is ¡the ¡heap ¡for? ¡ How ¡do ¡we ¡use ¡it? ¡
Autumn ¡2012 ¡ Memory ¡Alloca7on ¡