Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

‫بسم هللا‬

‫‪ #‬في البداية تعالوا نتكلم عن ال ‪ memory management‬وليه‬


‫أساسا انا محتاج حاجه زي ال ‪replacement algorithms‬‬
‫‪ -‬في عالم ال ‪ OS‬ال ‪ physical memory RAM‬صغيرة بعض‬
‫الشئ مقارنة بال ‪MAIN MEMOEY ROM‬‬
‫‪ -‬غالبا ما يحتاج البرنامج لعمل ‪ mapping‬لجزء من ال ‪ ROM‬كا‬
‫‪ VRAM‬يخزن فيها يخزن فيها جزء من البرنامج‬
‫‪ -‬بفرض ان اللي هيتعامل مع ال ‪ CPU‬مباشرة هو ال ‪ RAM‬من‬
‫خالل تنفيذ ال ‪ process‬الحالية‬
‫‪-‬تُخزن ال ‪ process‬في ال ‪ RAM‬علي هيئة ‪PAGEs‬‬
‫‪ -‬ماذا وان ‪ ..‬انا مخزن بالفعل ‪ process‬في ال ‪Physical‬‬
‫‪ memory‬لحد االمتالء – ومحتاج ادخل ‪ page‬جديدة ??‬
‫يحدث ما يسمي بال ‪Page Fault‬‬

‫‪ -‬العملية باختصار ان البرنامج ينفذ ‪( process‬مقسمة ل ‪) pages‬‬


‫ثم ينادي علي ال ‪ page‬اللي عليها الدور – وإذ بهذة ال‪ page‬غير‬
‫موجودة (‪)not loaded in RAM yet‬‬
‫هي في ال ‪ VRAM‬التمام العملية الزم ال‪ page‬تلود الي ال‬
‫‪ RAM‬لتجنب ال ‪ page fault‬والتمام ال ‪process‬‬
‫‪ -‬بسيطة !‬
‫هستبدل ‪ page‬سابقة من ال‬
‫‪physical memory‬‬
‫(هضحي بيها ‪)victim‬‬
‫وادخل ال‪ page‬الجديدة مكانها ‪..‬‬
‫عملية االستبدال هذه الزمها تنظيم وإدارة لتتم بفاعليه ‪ -‬وهنا‬ ‫‪‬‬

‫يلزمنا ال ‪ Replacement Algorithm‬لتنظيم عملية‬


‫االستبدال‪..‬‬
‫هناك طرق مختلفة لعمل التنظيم هذا اليكم بعض الطرق ‪..‬‬ ‫‪‬‬

‫‪FIFO – LRU – OPTIMAl‬‬


‫😊 ‪Open this document for the code with comment‬‬
‫شرح‬
This code is an implementation of the Page Replacement Algorithm in Java. The purpose of the
algorithm is to replace pages in memory that are not used to make room for pages that are
needed. There are three different methods of page replacement algorithms implemented in this
code: First-In-First-Out (FIFO), Least Recently Used (LRU), and Optimal.

First, the code declares several global variables including:

 int framesNum: The number of frames in memory


 int refString[]: The reference string or page requests
 int ne: Unused variable

The code contains three different methods to implement the different page replacement
algorithms.

1. First-In-First-Out (FIFO) The first method is the implementation of the FIFO


algorithm. It calculates the number of page faults that occur when using the FIFO
method. This method calculates the number of page faults by keeping track of the frames
in memory and checking if the current page is already in the memory. If it's not, it adds
the page to the next available frame and increments the number of page faults.

The memory state is stored in a 2D array called 'memory', and the state of the frames in
memory is stored in the 'inFrames' array.

Finally, the results are printed out with the 'printOneColumn' method.

2. Least Recently Used (LRU) The second method is the implementation of the LRU
algorithm. It calculates the number of page faults that occur when using the LRU method.

This method calculates the number of page faults by keeping track of the time that each page
was last used and replacing the page that was used least recently.

The 'time' array is used to keep track of the last time each page was used, and the memory
state is stored in a 2D array called 'mem'. The results are printed out with the
'printOneColumn' method.

3. Optimal The third method is the implementation of the Optimal algorithm. It calculates
the number of page faults that occur when using the Optimal method.

This method calculates the number of page faults by predicting the future use of pages and
replacing the page that will not be used for the longest time.

The 'inFrames' array is used to keep track of the pages in memory, and the 'inFramesNextIndex'
array is used to store the next index of each page in the reference string. The memory state is
stored in a 2D array called 'memory'. Finally, the results are printed out with the
'printOneColumn' method.

Finally, the 'main' method is used to call the three methods and run the algorithms. The user
can input the number of frames in memory and the reference string, and the output will be the
memory state and the number of page faults for each algorithm.

.........................................................................

‫الشرح التفصيلي للبرنامج‬


.. ‫هعمل ريكود لكل فانكش ان شاء هللا عشان الوقت‬

You might also like