You are on page 1of 5

CS 354 - Machine Organization

Monday, September 26, 2016

Homework hw2 (1.5%) due 10 pm TOMORROW Tuesday, September 27th


Project p2 (6%) due 10 pm Friday, October 7th

Last Time
File I/O and stdio.h
Where Do I Live?
C Memory Model
Address Space Layout
Today
Continue pages from last time
Heap Terms
brk (unistd.h)
Implicit Heap Allocator (stdlib.h)
Allocator Design
Next Time
Read: B&O 9.9.5 - 9.9.9
Allocator Implementation

Copyright 2016 Jim Skrentny

CS 354 (F16): L9 - 1

Heap Terms
Terms
Dynamic Memory:

 Why not simply allocate large amount of static memory to ensure sufficient capacity?

Heap:

Approaches
Implicit:

Explicit:

Copyright 2016 Jim Skrentny

CS 354 (F16): L9 - 2

brk (unistd.h)
What is unistd.h?

DIY Heap via Unix Calls


brk

int brk(void *addr)

void *sbrk(intptr_t incr)

Copyright 2016 Jim Skrentny

CS 354 (F16): L9 - 3

Implicit Heap Allocator (stdlib.h)


Whats in stdlib.h?

Heap Memory Allocators


void *malloc(size_t size)

Allocates and returns generic ptr to block of heap memory of size bytes,
memory double word aligned in Unix
void *calloc(size_t nItems, size_t size)

Allocates, clears to 0, and returns a block of heap memory of nItems * size bytes,

void *realloc(void *ptr, size_t size)


Reallocates to size bytes a previously allocated block of heap memory pointed to by ptr.

void free(void *ptr)

Frees the heap memory pointed to by ptr.

Copyright 2016 Jim Skrentny

CS 354 (F16): L9 - 4

Allocator Design
Goals
Throughput

Memory Utilization

Requirements

 List the requirements of a heap allocator.


1.

2.

3.

4.

5.

Design Considerations






Copyright 2016 Jim Skrentny

CS 354 (F16): L9 - 5

You might also like