List Allocation and Garbage Collection - PowerPoint PPT Presentation

1 / 22
About This Presentation
Title:

List Allocation and Garbage Collection

Description:

(define L (list 1 2 3)) (cons 1 (cons 2 (cons 3 ()))) Memory ... (define L (list 1 2 3)) (define M (list 4 5)) (define N (list 6 7 8)) Memory Allocation ... – PowerPoint PPT presentation

Number of Views:27
Avg rating:3.0/5.0
Slides: 23
Provided by: jjo102
Category:

less

Transcript and Presenter's Notes

Title: List Allocation and Garbage Collection


1
List Allocation and Garbage Collection
  • Example

2
Memory Allocation
0
1
AVAIL 0 ? (0 0 0 0 0 0 0 0) Initialize Heap
denotes list
0
0
2
1
0
3
2
0
4
3
0
5
4
0
6
5
0
7
6
0
-1
7
3
Memory Allocation
0
1
AVAIL 0 (define L (list 1 2 3)) ? (cons 1
(cons 2 (cons 3 ())))
0
0
2
1
0
3
2
0
4
3
0
5
4
0
6
5
0
7
6
0
-1
7
4
Memory Allocation
3
-1
AVAIL 1 (define L (list 1 2 3)) ? (cons 1
(cons 2 (cons 3 ())))
0
0
2
1
0
3
2
0
4
3
0
5
4
0
6
5
0
7
6
0
-1
7
5
Memory Allocation
3
-1
AVAIL 2 (define L (list 1 2 3)) ? (cons 1
(cons 2 (cons 3 ())))
0
2
0
1
0
3
2
0
4
3
0
5
4
0
6
5
0
7
6
0
-1
7
6
Memory Allocation
3
-1
AVAIL 3 ? (0 0 0 0 0) L 2 ? (1 2 3) (define
L (list 1 2 3)) ? (cons 1 (cons 2 (cons 3
())))
0
2
0
1
1
1
2
0
4
3
0
5
4
0
6
5
0
7
6
0
-1
7
7
Memory Allocation
3
-1
AVAIL 5 ? (0 0 0), L 2 ? (1 2 3), M 4 ?
(4 5) (define L (list 1 2 3)) (define M (list 4
5))
0
2
0
1
1
1
2
5
-1
3
4
3
4
0
6
5
0
7
6
0
-1
7
8
Memory Allocation
3
-1
AVAIL -1 ? NULL, L 2 ? (1 2 3), M 4 ? (4
5) N 7 ? (6 7 8) (define L (list 1 2
3)) (define M (list 4 5)) (define N (list 6 7 8))
0
2
0
1
1
1
2
5
-1
3
4
3
4
8
-1
5
7
5
6
6
6
7
9
Memory Allocation
3
-1
AVAIL -1 ? NULL, L 2 ? ((4 5) 2 3), M 4 ?
(4 5) N 7 ? (6 7 8) (define L (list 1 2
3)) (define M (list 4 5)) (define N (list 6 7
8)) (set-car! L M) overlap
0
2
0
1
4
1
2
5
-1
3
4
3
4
8
-1
5
7
5
6
6
6
7
10
Memory Allocation
3
-1
AVAIL -1 ? NULL, L 2 ? ((4 5) 2 3), M 0
int N 7 ? (6 7 8) (define L (list 1 2
3)) (define M (list 4 5)) (define N (list 6 7
8)) (set-car! L M) (define M 0) cells still
accessible
0
2
0
1
4
1
2
5
-1
3
4
3
4
8
-1
5
7
5
6
6
6
7
11
Memory Allocation
3
-1
AVAIL -1 ? NULL, L 2 ? ((4 5) 2 3), M 0
int N 0 int (define L (list 1 2
3)) (define M (list 4 5)) (define N (list 6 7
8)) (set-car! L M) (define M 0) (define N 0)
cells garbage
0
2
0
1
4
1
2
5
-1
3
4
3
4
8
-1
5
7
5
6
6
6
7
12
Garbage Collection
3
-1
AVAIL -1 ? NULL, L 2 ? ((4 5) 2 3), M 0
int N 0 int (define L (list 1 2
3)) (define M (list 4 5)) (define N (list 6 7
8)) (set-car! L M) (define M 0) (define N
0) (define N (list 1)) AVAIL NULL ? garbage
collection
0
2
0
1
4
1
2
5
-1
3
4
3
4
8
-1
5
7
5
6
6
6
7
13
Mark
3
-1
AVAIL -1 ? NULL, L 2 ? ((4 5) 2 3), M 0
int N 0 int (define L (list 1 2
3)) (define M (list 4 5)) (define N (list 6 7
8)) (set-car! L M) (define M 0) (define N
0) (define N (list 1)) Mark L
0
2
0
1
4
1
2
5
-1
3
4
3
4
8
-1
5
7
5
6
6
6
7
14
Mark
3
-1
AVAIL -1 ? NULL, L 2 ? ((4 5) 2 3), M 0
int N 0 int (define L (list 1 2
3)) (define M (list 4 5)) (define N (list 6 7
8)) (set-car! L M) (define M 0) (define N
0) (define N (list 1)) Mark L
0
2
0
1
4
1
2
5
-1
3
4
3
4
8
-1
5
7
5
6
6
6
7
15
Mark
3
-1
AVAIL -1 ? NULL, L 2 ? ((4 5) 2 3), M 0
int N 0 int (define L (list 1 2
3)) (define M (list 4 5)) (define N (list 6 7
8)) (set-car! L M) (define M 0) (define N
0) (define N (list 1)) Mark L
0
2
0
1
4
1
2
5
-1
3
4
3
4
8
-1
5
7
5
6
6
6
7
16
Mark
3
-1
AVAIL -1 ? NULL, L 2 ? ((4 5) 2 3), M 0
int N 0 int (define L (list 1 2
3)) (define M (list 4 5)) (define N (list 6 7
8)) (set-car! L M) (define M 0) (define N
0) (define N (list 1)) Mark L
0
2
0
1
4
1
2
5
-1
3
4
3
4
8
-1
5
7
5
6
6
6
7
17
Mark
3
-1
AVAIL -1 ? NULL, L 2 ? ((4 5) 2 3), M 0
int N 0 int (define L (list 1 2
3)) (define M (list 4 5)) (define N (list 6 7
8)) (set-car! L M) (define M 0) (define N
0) (define N (list 1)) Mark L
0
2
0
1
4
1
2
5
-1
3
4
3
4
8
-1
5
7
5
6
6
6
7
18
Sweep
3
-1
AVAIL 5 ? (0) L 2 ? ((4 5) 2 3), M 0
int N 0 int (define L (list 1 2
3)) (define M (list 4 5)) (define N (list 6 7
8)) (set-car! L M) (define M 0) (define N
0) (define N (list 1)) Reclaim unmarked cells
0
2
0
1
4
1
2
5
-1
3
4
3
4
0
-1
5
7
5
6
6
6
7
19
Sweep
3
-1
AVAIL 6 ? (0 0) L 2 ? ((4 5) 2 3), M 0
int N 0 int (define L (list 1 2
3)) (define M (list 4 5)) (define N (list 6 7
8)) (set-car! L M) (define M 0) (define N
0) (define N (list 1)) Reclaim unmarked cells
0
2
0
1
4
1
2
5
-1
3
4
3
4
0
-1
5
0
5
6
6
6
7
20
Sweep
3
-1
AVAIL 7 ? (0 0 0) L 2 ? ((4 5) 2 3), M 0
int N 0 int (define L (list 1 2
3)) (define M (list 4 5)) (define N (list 6 7
8)) (set-car! L M) (define M 0) (define N
0) (define N (list 1)) Reclaim unmarked cells
0
2
0
1
4
1
2
5
-1
3
4
3
4
0
-1
5
0
5
6
0
6
7
21
Sweep
3
-1
AVAIL 7 ? (0 0 0) L 2 ? ((4 5) 2 3), M 0
int N 0 int (define L (list 1 2
3)) (define M (list 4 5)) (define N (list 6 7
8)) (set-car! L M) (define M 0) (define N
0) (define N (list 1)) Unmark cells
0
2
0
1
4
1
2
5
-1
3
4
3
4
0
-1
5
0
5
6
0
6
7
22
Memory Allocation
3
-1
AVAIL 6 ? (0 0) L 2 ? ((4 5) 2 3), M 0
int N 7 ? (1) (define L (list 1 2
3)) (define M (list 4 5)) (define N (list 6 7
8)) (set-car! L M) (define M 0) (define N
0) (define N (list 1))
0
2
0
1
4
1
2
5
-1
3
4
3
4
0
-1
5
0
5
6
1
-1
7
Write a Comment
User Comments (0)
About PowerShow.com