Docsity

Dynamic Memory Allocation: Understanding Heap Management in Operating Systems - Prof. Mich, Study notes of Computer Science

Partial preview of the text

Download Dynamic Memory Allocation: Understanding Heap Management in Operating Systems - Prof. Mich and more Study notes Computer Science in PDF only on Docsity!

CS 351 : Saelee

Dynamic Memory

Allocation

Disk Virtual Memory 0 0xFFFFFFFF

Process view

Physical Memory

OS implementation

details

Static data

(we don’t need to worry about this)

  • code, global variables, compiler jump tables, etc.
  • allocated at fork/exec
  • never deallocated!

The Stack

as stack grows, pages

allocated as needed

(up to preset stack limit)

  • function activation records
    • local vars, arguments, return values
  • alloc= push ; dealloc= pop
  • object lifetime: LIFO

The Heap

brk

  • starts out empty
  • brk pointer marks top of the heap void sbrk(int inc); _/ resizes heap by inc, returns old brk value */_

The Heap

hp

void *hp = sbrk( N );

brk

N

note: granularity of

N is page size

(really) naive malloc

void *malloc(size_t size)

void *p = sbrk(newsize);

if (p == -­‐ 1 )

return NULL;

else

return p;

free?

must support allocation & deallocation

User Process Disk RAM dynamic memory allocator sbrk Heap application program malloc OS kernel

basic issues:

  • tracking free space
  • tracking allocated blocks
  • storing block metadata

API?

explicit memory management

vs. garbage collection (implicit mem management)