Thread: Cache Simulator

  1. #1
    Join Date
    Mar 2010

    Cache Simulator


    I have two methods to write in this cache simulator:

    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <math.h>
    #include <assert.h>
    struct cache_blk_t {
      unsigned long tag;
      char valid;
      char dirty;
      cache_blk_t *way_next;
      cache_blk_t *way_prev;
    struct cache_set_t {
      cache_blk_t *way_head;
      cache_blk_t *way_tail;
      unsigned int FIFO_counter;
    enum cache_policy {
    struct cache_t {
      int nsets;		// # sets
      int bsize;		// block size
      int assoc;		// associativity
      enum cache_policy policy;
      // statistics
      unsigned long accesses;
      unsigned long hits;
      unsigned long misses;
      unsigned long replacements;
      unsigned long writebacks;
      struct cache_set_t *sets;
    cache_create(int A, int B, int C, enum cache_policy policy)
      create cache based on A, B, and C
      allocate sets
      allocate blocks in each set
      remember the replacement policy setting
      initialize statistics data
    cache_access(struct cache_t *cp, unsigned long address, char access_type)
      based on address determine the set to access in cp
      examine blocks in the set to check hit/miss
      if miss, determine the victim in the set to replace
      if LRU is used, update the block list
    In the Cache create, and cache access method, can anyone help translate my sudo code?


  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Ok, first, create a cache based on A, B and C. Then, allocate sets. Allocate blocks for each set. Remember your replacement policy settings. Initialize the statistics data. That'll cover the cache_create function.

    Next, the cache_access function, based on the address, determine the set to access. Look at the blocks in the set and see where you have hits and misses, and handle accordingly.

    See, you're just going to get smart ass answers until you tell us specifically what you have problems with. No, we're not going to "translate your sudo code" into real code for you.

    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. need help with cache simulator!
    By dtogers123 in forum C Programming
    Replies: 3
    Last Post: 04-30-2008, 06:18 PM
  2. Resource manager tree
    By VirtualAce in forum Game Programming
    Replies: 23
    Last Post: 09-07-2007, 10:27 PM
  3. added start menu crashes game
    By avgprogamerjoe in forum Game Programming
    Replies: 6
    Last Post: 08-29-2007, 01:30 PM
  4. cache miss/hit
    By xddxogm3 in forum C++ Programming
    Replies: 3
    Last Post: 05-07-2007, 06:51 PM
  5. destroywindow() problem
    By algi in forum Windows Programming
    Replies: 6
    Last Post: 03-27-2005, 11:40 PM