Contur 2
Educational OS kernel simulator
Loading...
Searching...
No Matches
contur::OptimalReplacement Class Referencefinal

Optimal page replacement (Belady's algorithm). More...

#include <optimal_replacement.h>

Inheritance diagram for contur::OptimalReplacement:

Public Member Functions

 OptimalReplacement (std::vector< FrameId > futureAccesses)
 Constructs with a known future access sequence.
 ~OptimalReplacement () override
 Destroys optimal replacement policy.
 OptimalReplacement (const OptimalReplacement &)=delete
 Copy construction is disabled.
OptimalReplacementoperator= (const OptimalReplacement &)=delete
 Copy assignment is disabled.
 OptimalReplacement (OptimalReplacement &&) noexcept
 Move-constructs policy state.
OptimalReplacementoperator= (OptimalReplacement &&) noexcept
 Move-assigns policy state.
std::string_view name () const noexcept override
 Returns the name of the algorithm (e.g., "FIFO", "LRU").
FrameId selectVictim (const PageTable &pageTable) override
 Selects a victim frame to evict.
void onAccess (FrameId frame) override
 Notifies the policy that a frame was accessed (read or write).
void onLoad (FrameId frame) override
 Notifies the policy that a new page was loaded into a frame.
void reset () override
 Resets the policy's internal state.
Public Member Functions inherited from contur::IPageReplacementPolicy
virtual ~IPageReplacementPolicy ()=default

Private Attributes

std::unique_ptr< Impl > impl_

Detailed Description

Optimal page replacement (Belady's algorithm).

Evicts the page that will not be used for the longest time in the future. Requires the complete future access sequence to be known in advance. This is impractical for real systems but serves as a theoretical baseline for comparing other algorithms' performance.

Definition at line 19 of file optimal_replacement.h.

Constructor & Destructor Documentation

◆ OptimalReplacement() [1/3]

contur::OptimalReplacement::OptimalReplacement ( std::vector< FrameId > futureAccesses)
explicit

Constructs with a known future access sequence.

Parameters
futureAccessesOrdered list of FrameIds that will be accessed.

Referenced by operator=(), operator=(), OptimalReplacement(), and OptimalReplacement().

◆ ~OptimalReplacement()

contur::OptimalReplacement::~OptimalReplacement ( )
override

Destroys optimal replacement policy.

◆ OptimalReplacement() [2/3]

contur::OptimalReplacement::OptimalReplacement ( const OptimalReplacement & )
delete

Copy construction is disabled.

References OptimalReplacement().

◆ OptimalReplacement() [3/3]

contur::OptimalReplacement::OptimalReplacement ( OptimalReplacement && )
noexcept

Move-constructs policy state.

References OptimalReplacement().

Member Function Documentation

◆ name()

std::string_view contur::OptimalReplacement::name ( ) const
nodiscardoverridevirtualnoexcept

Returns the name of the algorithm (e.g., "FIFO", "LRU").

Implements contur::IPageReplacementPolicy.

References name().

Referenced by name().

◆ onAccess()

void contur::OptimalReplacement::onAccess ( FrameId frame)
overridevirtual

Notifies the policy that a frame was accessed (read or write).

Implements contur::IPageReplacementPolicy.

References onAccess().

Referenced by onAccess().

◆ onLoad()

void contur::OptimalReplacement::onLoad ( FrameId frame)
overridevirtual

Notifies the policy that a new page was loaded into a frame.

Implements contur::IPageReplacementPolicy.

References onLoad().

Referenced by onLoad().

◆ operator=() [1/2]

OptimalReplacement & contur::OptimalReplacement::operator= ( const OptimalReplacement & )
delete

Copy assignment is disabled.

References OptimalReplacement().

◆ operator=() [2/2]

OptimalReplacement & contur::OptimalReplacement::operator= ( OptimalReplacement && )
noexcept

Move-assigns policy state.

References OptimalReplacement().

◆ reset()

void contur::OptimalReplacement::reset ( )
overridevirtual

Resets the policy's internal state.

Implements contur::IPageReplacementPolicy.

References reset().

Referenced by reset().

◆ selectVictim()

FrameId contur::OptimalReplacement::selectVictim ( const PageTable & pageTable)
nodiscardoverridevirtual

Selects a victim frame to evict.

Parameters
pageTableThe current page table state.
Returns
The FrameId of the frame to evict.

Implements contur::IPageReplacementPolicy.

References selectVictim().

Referenced by selectVictim().

Member Data Documentation

◆ impl_

std::unique_ptr<Impl> contur::OptimalReplacement::impl_
private

Definition at line 57 of file optimal_replacement.h.


The documentation for this class was generated from the following file: