Solution:
This solution is after Andreas Reifert, a distinguished student in the
class of Fall 1999.
(x) A yK - means: in step x we allocate yK of memory
(x) D (y) - means: in step x we deallocate the memory allocated in
step y
Best fit outperforms:
(1) A 5K
(2) A 8K
(3) A 3K - buddy cannot do this
(4) D (1)
(5) D (3)
(6) A 3K - first and worst take the 5K part, best the 3K part
(7) A 5K - first and worst cannot do this, best can
#
Worst fit outperforms:
(1) A 3K
(2) A 8K
(3) A 5K - buddy cannot do this
(4) D (1)
(5) D (3)
(6) A 2K - first and best take the 3K part, worst the 5K part
(7) A 3K - first and best take the 5K part, worst a 3K
(8) A 3K - first and best cannot do this, worst can
First fit outperforms:
(1) A 4K
(2) A 2K
(3) A 2K
(4) A 3K
(5) A 5K - buddy cannot do this
(6) D (1)
(7) D (3)
(8) D (5)
(9) A 1K - best takes the 2K part, worst the 5K part, first
the 4K part
(10) A 3K - best takes the 4K part, worst a 4K part, first the
3K part
(11) A 2K - best takes the 5K part, worst the 4K part, first
the 2K part
(12) A 5K - best and worst cannot do this, first can
Buddy outperforms:
(1) A 2K
(2) A 4K
(3) A 8K
(4) D (1) - only buddy can merge the 2K with the neighbouring 2K to
a 4K part
(5) A 4K - best, worst and first cannot do this, buddy can
Solution:
Each partition will need the following data structure:
typedef struct
{
unsigned base_address;
// starting address of the partition
unsigned size; &nb\
sp;
// size of the partition in bytes
enum {free, in_use} status;
// status of the partition
}
PartitionRecord;
Then, we need to implement a data structure that
contains the partition records and such that:
* partition records are sorted by size
* partition records can be inserted into the
data structure efficiently
* partition records can removed from the data
structure efficiently
* the smallest partition larger than a particular
size can be located efficiently
* allows a partition to be checked against its adjacent neighbors so
that it can be merged with them if they are all free (or a subset thereof)
There is no known data structure that can achieve all these feats simultaneously. There are however two reasonable alternatives:
4 bit segment number | 12 bit page number | 16 bit offset |
Here are the relevant tables (all values in dexadecimal):
Segment Table | Page Table A | Page Table B | |||||
0 | Page Table A | 0 | CAFE | 0 | F000 | ||
1 | Page Table B | 1 | DEAD | 1 | D8BF | ||
x | (rest invalid) | 2 | BEEF | x | (rest invalid) | ||
3 | BA11 | ||||||
x | (rest invalid) |
Solution:
Need solution