Calculating number of page faults for 2-d array

后端 未结 4 528
天命终不由人
天命终不由人 2021-02-05 12:11

I am trying to study for an exam..and I found this example but can\'t understand how they got the answer. Can anyone explain it please?

Question:

4条回答
  •  独厮守ぢ
    2021-02-05 12:51

    So there's 50 pages total in the 2-d array stored either row by row, or column by column.

    If you store pages row by row and you access them row by row, your going to access the same page over and over again until you get to the next page, so you switch pages (causing a page fault) only 50 times because there's 50 pages.

    If you store pages row by row, and access them column by column (or vise-verse), your going to get an element from one page, switch pages, get one from another page, switch pages, etc. So your still going through 50 pages, but you switch 100 times for every page.

    Imaging your reading a paper. If you read one page at a time, your gonna turn the page once for every page. If you read one line off every page, then start over and read the second line, third line etc. your going to have to flip through the whole paper over and over, for every line on a page (assuming all pages have the same number of lines like an array would)...each time you turn the page is a page fault.

提交回复
热议问题