了解OPT算法 [英] Understanding OPT Algorithm

查看:992
本文介绍了了解OPT算法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好了,我想了解OPT算法,那么它会很容易让我$ C C是$。 我不能跟着一起滑及其制作没有任何意义。有人可以走路我通过它通过在如何做到这一点一步一步?

Okay, i am trying to understand OPT algorithm then it will make it easy for me to code it. I cant follow along with the slide and its making no sense. Can someone walk me through it step by step on how to do it?

这看起来与LRU算法。难道我们保持第二阵列,柜台?

This looks identical to the LRU algorithm. Do we keep a second array with a counter?

推荐答案

您显然必须事先了解哪些页面将要使用的以及按什么顺序;这是列表 1,2,3,...,4,5 在你的榜样。如果必须更换页面,选择包含的页面将使用最后在所有他们的框架。

You apparently must know in advance which pages are going to be used and in what order; this is the list 1, 2, 3, ..., 4, 5 in your example. When you must replace a page, you choose the frame containing the page that will be used last amongst all of them.

在这个例子中,您可以访问,1页2 3 4,1,2,没有任何页面错误(因为所有的网页正在换入)。

In this example, you access pages 1, 2, 3, 4, 1, and 2 without any page faults (since all pages are currently swapped in).

您的下一个页面的访问,第5页,是不是在任何帧,所以你必须选择一个框架来把它变成。基于即将到来的页面命中(1,2,3,4),第4页(在帧4)将是最后被访问,所以你换页5到帧4(如图中的图)。

Your next page access, page 5, is not in any frame, so you must choose a frame to put it into. Based on upcoming page hits (1, 2, 3, 4), page 4 (in frame 4) will be last to be accessed, so you swap page 5 into frame 4 (as shown in your diagram).

接下来页,1,2,和3被访问而没有任何故障。

The next pages, 1, 2, and 3 are accessed without any fault.

现在4页的访问,但它是previously换出,所以你有一个页面错误。你即将到来的访问列表仅显示5页将需要,因此任何的1,2和3可以被换出。选择1,presumably,因为它是第一个。

Now page 4 is accessed but it was previously swapped out so you have a page fault. Your list of upcoming accesses shows only page 5 will be needed, so any of 1, 2, and 3 may be swapped out. 1 was chosen, presumably because it is first.

这篇关于了解OPT算法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆