Peter Mawhorter
Write your questions on the boards.
malloc
and free
From the user’s perspective:
malloc
requests some memory.
NULL
if there’s not enough memory
available.free
gives back allocated memory.
malloc
gave
you.malloc
and free
From the system’s perspective:
malloc
requests some memory.
free
gives back allocated memory.
malloc
callmovaps
require alignment:
malloc
are 16-byte aligned.(unused) | ← heap origin (16-byte aligned) |
---|---|
80/a/f | ← block header (off-by-8 from aligned) |
← start of block data (16-byte aligned) | |
80 | ← block footer |
0/f/a | ← heap footer |
(Alignment means last 4 bits are always 0; don’t need extra room for flags)
A = malloc(5)
(unused) | ← heap origin |
---|---|
16/a/a | ← block header |
← A (aligned; 8 ≥ 5 bytes) | |
64/a/f | ← block header |
64 | ← block footer |
0/f/a | ← heap footer |
A = malloc(5)
; B = malloc(15)
(unused) | ← heap origin |
---|---|
16/a/a | ← block header |
← A | |
32/a/a | ← block header |
← B (24 ≥ 15 bytes) | |
32/a/f | ← block header |
32 | ← block footer |
0/f/a | ← heap footer |
A = malloc(5)
; B = malloc(15); free(A);
(unused) | ← heap origin |
---|---|
16/a/f | ← block header |
16 | |
32/f/a | ← block header |
← B (24 ≥ 15 bytes) | |
32/a/f | ← block header |
32 | ← block footer |
0/f/a | ← heap footer |
A = malloc(5)
;
B = malloc(15); free(A); free(B);
(unused) | ← heap origin |
---|---|
16/a/f | ← block header |
16 | |
32/f/f | ← block header (fragmented) |
32 | |
32/f/f | ← block header |
32 | ← block footer |
0/f/a | ← heap footer |
A = malloc(5)
;
B = malloc(15); free(A); free(B);
(unused) | ← heap origin |
---|---|
80/a/f | ← block header (consolidated) |
80 | ← block footer |
0/f/a | ← heap footer |
We’ve only allocated 2/80 bytes, but we cannot allocate the requested 25 bytes :(
(unused) | ← heap origin |
---|---|
16/a/a | ← block header |
← A | |
32/a/f | ← block header |
32 | ← block footer |
16/f/a | ← block header |
← C | |
16/a/f | ← block header |
16 | ← block footer |
0/f/a | ← heap footer |
Group yourself:
(The document does not contain full instructions; just the questions you need to answer.)