827 - Buddy Memory Allocator
Posted: Mon Nov 04, 2002 1:12 am
Is there any trick with this problem? Does anyone have an interesting input?
Thanks a lot!
Thanks a lot!
What does 'most recently declared free' mean??Notice that, whenever there is a request that corresponds to a block of size s, your program should select the block of that size that was most recently declared free. Furthermore, when a block is split in two, the left-one (lower addresses) should be selected before the right-one.
and the expected output:7
10 4
A 70
B 35
C 80
A 0
D 60
B 0
10 4
A 70
B 35
C 80
A 0
D 60
B 0
C 0
10 4
A 70
B 35
C 80
A 0
D 60
B 0
D 0
10 4
A 70
B 35
C 80
A 0
D 60
B 0
C 0
D 0
10 4
A 70
B 35
C 80
A 0
D 60
B 0
D 0
C 0
10 4
10 4
A 70
A 0
It would be useful to also try a few tests where there a choice between what block to allocate - The program should choose most recently freed block/block which was most recently created from splitting a larger block (with the lower address block given preference).Hole:128
Hole:64
D:60
C:80
Hole:128
Hole:512
Hole:128
Hole:64
D:60
Hole:256
Hole:512
Hole:256
C:80
Hole:128
Hole:512
Hole:1024
Hole:1024
Hole:1024
Hole:1024
Code: Select all
2
10 2
A 2
C 64
A 0
E 64
F 64
10 2
A 2
C 64
A 0
C 0
E 64
F 64
2.Whenever possible, an unnallocated buddy is merged with a companion buddy in order to form a larger free block.
First sentence leads to solution, in which we should, after termination of executed program, create as large free block as possible (I think binary tree is very good to do this). Second sentence suggest us that we can't create as large free block as possible, because we loose information about most recently declared free block of memory !!Notice that, whenever there is a request that corresponds to a block of size s, your program should select the block of that size that was most recently declared free.
Code: Select all
4
10 2
A 2
C 64
A 0
E 64
F 64
10 2
A 2
C 64
A 0
C 0
E 64
F 64
10 2
A 128
B 512
B 0
A 0
C 256
10 2
A 64
B 64
C 64
D 64
B 0
C 0
E 64
Code: Select all
E:64
C:64
F:64
Hole:64
Hole:256
Hole:512
E:64
F:64
Hole:128
Hole:256
Hole:512
C:256
Hole:256
Hole:512
A:64
Hole:64
E:64
D:64
Hole:256
Hole:512