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

An overview of dynamic memory allocation in operating systems, focusing on the management of the heap. Topics covered include the stack, heap, brk and sbrk functions, and the implementation of a simple malloc function. The document also discusses the goals of dynamic memory allocation, such as maximizing throughput and heap utilization, and the comparison between explicit memory management and garbage collection.

Typology: Study notes

Pre 2010

Uploaded on 12/09/2010

jsmith-8140
jsmith-8140 🇺🇸

5

(1)

9 documents

1 / 46

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CS351 : Saelee
Dynamic Memory
Allocation
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e

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)