diff options
Diffstat (limited to 'secondchance.py')
-rw-r--r-- | secondchance.py | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/secondchance.py b/secondchance.py new file mode 100644 index 0000000..b0fb1f9 --- /dev/null +++ b/secondchance.py | |||
@@ -0,0 +1,34 @@ | |||
1 | #!/usr/bin/env python3 | ||
2 | |||
3 | # UPEM / Programmation système / Projet : Simulation de gestion de mémoire virtuelle | ||
4 | # Pacien TRAN-GIRARD et Adam NAILI | ||
5 | |||
6 | from mem import Memory | ||
7 | from pageexception import * | ||
8 | |||
9 | |||
10 | class SecondChancePaginator: | ||
11 | def __init__(self, mem): | ||
12 | self.mem = mem | ||
13 | self._check_table = [0 for _ in range(len(mem.main)+len(mem.virt))] | ||
14 | self._main_cursor = 0 | ||
15 | |||
16 | def _put_main(self, page): | ||
17 | overwritten = self.mem.main[self._main_cursor] | ||
18 | while(overwritten is not None and self._check_table[overwritten] == 1): | ||
19 | self._main_cursor=(self._main_cursor + 1) % len(self.mem.main) | ||
20 | self._check_table[overwritten] = 0 | ||
21 | overwritten = self.mem.main[self._main_cursor] | ||
22 | self.mem.main[self._main_cursor] = page | ||
23 | self._main_cursor = (self._main_cursor + 1) % len(self.mem.main) | ||
24 | return overwritten | ||
25 | |||
26 | def load(self, page): | ||
27 | if not self.mem.page_in_range(page): raise PageException | ||
28 | if page in self.mem.main: | ||
29 | self._check_table[page] = 1 | ||
30 | return | ||
31 | if page in self.mem.virt: self.mem.remove_virt(page) | ||
32 | overwritten = self._put_main(page) | ||
33 | if overwritten is not None: self.mem.put_virt(overwritten) | ||
34 | |||