Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

CS 354 - Machine Organization

Wednesday, September 28, 2016

Homework hw3 (1.5%) due 10 pm Tuesday, October 4th


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

Last Time
Continue pages
Heap Terms
brk (unistd.h)
Today
Implicit Heap Allocator (stdlib.h) (from last time)
Allocator Design (from last time)
A Bit of Linux
Simple View of Heap
Free Block Organization
Next Time
Read: B&O 9.9.10 - 9.9.11
Implicit Free List

Copyright 2016 Jim Skrentny

CS 354 (F16): L10 - 1

A Bit of Linux
Program Size
size <executable or object_file>

%gcc -m32 myProg.c


%size a.out
text
data
1029
276

bss
4

dec
1309

hex filename
51d a.out

Virtual Address Space Maps

%cat /proc/<pid_of_process>/maps

%cat /proc/self/maps

Process and Job Control

ps jobs &ctrl+z bg fg ctrl+c kill -

Copyright 2016 Jim Skrentny

CS 354 (F16): L10 - 2

Simple View of Heap

Diagram Layout
0x_00

0x_08

1 byte

0x_10

0x_18

1 word
= 4 bytes

0x_20

0x_28

0x_30

0x_38

0x_40

0x_28

0x_30

0x_38

0x_40

double word
= 8 bytes

double word aligned blocks:

Heap Allocation Run 1


0x_00

0x_08

0x_10

0x_18

0x_20

 Update the diagram to show the following heap allocations:


1)
2)
3)
4)

p1
p2
p3
p4

=
=
=
=

malloc(2
malloc(3
malloc(4
malloc(5

*
*
*
*

sizeof(int));
sizeof(char));
sizeof(int));
sizeof(int));

 What happens with the following heap operations:


5) free(p1);
6) free(p3);
7) p5 = malloc(6 * sizeof(int));

Internal Fragmentation:

External Fragmentation:

Copyright 2016 Jim Skrentny

CS 354 (F16): L10 - 3

Free Block Organization


 How does allocator know which parts of the heap are free and which are allocated?
 How does allocator know how big each block is?

Explicit Free List

0x_00

0x_08

0x_10

0x_18

0x_20

0x_28

0x_30

0x_38

0x_40

Implicit Free List

Copyright 2016 Jim Skrentny

CS 354 (F16): L10 - 4

You might also like