Class: CacheSim::Slot

Inherits:
Object
  • Object
show all
Defined in:
cache_simulation.rb

Overview

This class creates the slots. Initialization:

slot = CacheSim::Slot.new(num, is_dirty, is_valid, tag, saved_blocks)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(num, is_dirty, is_valid, tag, saved_blocks) ⇒ Slot

Note:

Generally you will want to initialize slots as empty. See the example.

Initalizes new Slot object

Examples:

Create a new slot

Slot.new("1a", 0, 0, 0, [0, 0, 0, 0])

Parameters:

  • num (String)

    slot number, doesn't change after initialization, hexadecimal

  • is_dirty (Boolean)

    flag to check if slot is dirty. 1 if dirty, 0 otherwise

  • is_valid (Boolean)

    flag to check if slot has valid data. 1 if valid, 0 otherwise

  • tag (String)

    current tag saved in slot

  • saved_blocks (Array)

    array of blocks currently saved in the cache



48
49
50
51
52
53
54
# File 'cache_simulation.rb', line 48

def initialize(num, is_dirty, is_valid, tag, saved_blocks)
  @num = num
  @is_dirty = is_dirty
  @is_valid = is_valid
  @tag = tag
  @saved_blocks = saved_blocks
end

Instance Attribute Details

#is_dirtyBoolean

Returns whether a slot currently is dirty (has content not copied to main memory)

Returns:

  • (Boolean)

    1 if dirty, 0 otherwise



29
30
31
# File 'cache_simulation.rb', line 29

def is_dirty
  @is_dirty
end

#is_validBoolean

Returns whether a slot currently has valid content or not

Returns:

  • (Boolean)

    1 if valid, 0 otherwise



26
27
28
# File 'cache_simulation.rb', line 26

def is_valid
  @is_valid
end

#numString (readonly)

Gets the current slot number

Returns:

  • (String)

    hexadecimal slot number



23
24
25
# File 'cache_simulation.rb', line 23

def num
  @num
end

#saved_blocksArray

Returns array of saved blocks. Defaults to array of zeros if empty.

Returns:

  • (Array)

    array of blocks currently in cache



35
36
37
# File 'cache_simulation.rb', line 35

def saved_blocks
  @saved_blocks
end

#tagString

Returns current hexadecimal tag in the slot

Returns:

  • (String)

    hexadecimal tag number



32
33
34
# File 'cache_simulation.rb', line 32

def tag
  @tag
end