Loading

bustub project1整理

TASK1 实现LRUReplacer类

LRUReplacer类继承自Replacer类。ClockReplacer类也继承自Replacer类,但本次实验不准备实现Replacer类。

类成员变量

//都是我自己定义的
using time_stamp = uint32_t;
time_stamp cur_time_;
//unpinned_frames_保存着那些没有被Pin的Page所在的frame
std::list<std::pair<frame_id_t, time_stamp>> unpinned_frames_;

成员函数

//构造函数
LRUReplacer::LRUReplacer(size_t num_pages);
//析构函数
LRUReplacer::~LRUReplacer();
//从frames中选出一个按最近访问时间排序排名最靠后的一个frame,成功则将该frame的id保存在frame_id中,并返回true。如果frames_为空,则返回false。
auto LRUReplacer::Victim(frame_id_t *frame_id) -> bool;
//当BufferPoolManager对某个Page进行Pin操作时,需要将该Page所在的frame从unpinned_frames_中移除。
void LRUReplacer::Pin(frame_id_t frame_id);
//当某个Page被Unpin至pin_count_将为0时,执行这个函数,将该Page对应的frame放入unpinned_frames_。
void LRUReplacer::Unpin(frame_id_t frame_id);
//返回当前LRUReplacer中保存的frame数,即unpinned_frames_的大小。
auto LRUReplacer::Size() -> size_t;
posted @ 2022-07-16 22:28  雨下yi整晚  阅读(118)  评论(0)    收藏  举报