-->
当前位置:首页 > 题库

PROGRAMMING:Memory partition allocation -- first adaptation algorithm

Luz5年前 (2021-05-10)题库480
Input the size of memory and the threshold min size, and allocate the partition continuously according to the first adaptation algorithm. When partitioning, if the remaining memory is less than or equal to minsize, the whole block of memory will be allocated to the process and will not be partitioned.
Select the corresponding operation according to the menu:
1. Initialization: enter the size of memory and the threshold minsize. In the initial state, the name of free partition is "void".
2. Allocation: enter the name and size of the application process.
*If it can be allocated, it will display "allocation succeeded!";
*If the remaining space is insufficient, the reason for not allocating "insufficient remaining space, not allocated" will be displayed;
*If the remaining space can be redistributed through compact technology, it will prompt "do you want to redistribute through compact technology( Y / N) "if" Y "is selected, it will be divided and allocated again through compact technology. After successful allocation, it will display" allocation succeeded! " If "n" is selected, the output "there is no suitable space left, no allocation"
3. Recycle: enter the name of the recycle process. If there are adjacent free partitions, merge them and output "recycle succeeded!"; If the input error, prompt "check no this partition!"
4. Display: display the current memory allocation status.
0. Exit
Other: output "input error, please input again."
###Input format:
After initialization, operate according to the menu.
###Output format:
The menu is displayed only once and output according to the corresponding selection.
###Input sample 1:
Here is a set of inputs. For example:
```in
one
1024 5
four
0
```
###Output sample 1:
The corresponding output is given here. For example:
```out
1. Initialization
2. Distribution
3. Recycling
4. Display
0. Exit
Please select:
Partition number partition start address end address size current status
1 void 0 1023 1024 idle
```
###Input sample 2:
Here is a set of inputs. For example:
```in
one
1000 5
two
A 100
two
B 200
two
C 150
two
D 250
two
E 200
two
F 95
four
0
```
###Output sample 2:
The corresponding output is given here. For example:
```out
1. Initialization
2. Distribution
3. Recycling
4. Display
0. Exit
Please select:
Distribution successful!
Distribution successful!
Distribution successful!
Distribution successful!
Distribution successful!
Distribution successful!
Partition number partition start address end address size current status
1 a 0 99 100 allocated
2 B 100 299 200 allocated
3 C 300 449 150 allocated
4 d 450 699 250 allocated
5 e 700 899 200 allocated
6 F 900 999 100 assigned
```
###Input sample 3:
Here is a set of inputs. For example:
```in
one
1000 5
two
A 100
two
B 200
two
C 150
two
D 250
two
E 200
two
F 150
four
0
```
###Output sample 3:
The corresponding output is given here. For example:
```out
1. Initialization
2. Distribution
3. Recycling
4. Display
0. Exit
Please select:
Distribution successful!
Distribution successful!
Distribution successful!
Distribution successful!
Distribution successful!
The remaining space is insufficient and will not be allocated.
Partition number partition start address end address size current status
1 a 0 99 100 allocated
2 B 100 299 200 allocated
3 C 300 449 150 allocated
4 d 450 699 250 allocated
5 e 700 899 200 allocated
6 void 900 999 100 idle
```
###Input sample 4:
Here is a set of inputs. For example:
```in
one
1000 5
two
A 100
two
B 200
two
C 150
two
D 250
two
E 200
two
F 150
three
A
four
0
```
###Output sample 4:
The corresponding output is given here. For example:
```out
1. Initialization
2. Distribution
3. Recycling
4. Display
0. Exit
Please select:
Distribution successful!
Distribution successful!
Distribution successful!
Distribution successful!
Distribution successful!
The remaining space is insufficient and will not be allocated.
Recycle success!
Partition number partition start address end address size current status
1 void 0 99 100 idle
2 B 100 299 200 allocated
3 C 300 449 150 allocated
4 d 450 699 250 allocated
5 e 700 899 200 allocated
6 void 900 999 100 idle
```
###Input sample 5:
Here is a set of inputs. For example:
```in
one
1000 5
two
A 100
two
B 200
two
C 150
two
D 250
two
E 200
two
F 150
three
A
two
X 150
Y
four
0
```
###Output sample 5:
The corresponding output is given here. For example:
```out
1. Initialization
2. Distribution
3. Recycling
4. Display
0. Exit
Please select:
Distribution successful!
Distribution successful!
Distribution successful!
Distribution successful!
Distribution successful!
The remaining space is insufficient and will not be allocated.
Recycle success!
Is it through compact technology to re divide( Y/N)
Distribution successful!
Partition number partition start address end address size current status
1 b 0 199 200 allocated
2 C 200 349 150 allocated
3 D 350 599 250 allocated
4 E 600 799 200 allocated
5 x 800 949 150 allocated
6 void 950 999 50 free
```






answer:If there is no answer, please comment