【发布时间】:2014-04-06 14:07:53
【问题描述】:
因此,对于我的计算机体系结构课程,我必须在 C# 上模拟缓存/内存关系,但我只是不确定缓存如何实际存储数据。我得到了缓存标签的概念,但我真的没有得到偏移量。
假设我有一个可容纳 256 个 32 位整数的 RAM。我想拥有一个缓存系统,其中我有一个包含 8 个 32 位整数的缓存。但是然后在缓存中的那些 32 位整数中,我需要添加标记和有效位,这使其大致缩小到 26 位左右。那么如何将 32 位数据存储在剩下的 26 位中呢?
这是我现在拥有的代码,它仍在进行中
class Memory
{
public List<UInt32> instructions = new List<UInt32>();
const int directCacheSize = 8;
ulong[] directCache = new ulong[directCacheSize];
private int[] stack = new int[256];
public int this[int i]
{
get
{
int directMapIndex = i % directCacheSize;
if (directCache[directMapIndex] == Convert.ToUInt64(stack[i]))
{
return Convert.ToInt32(directCache[directMapIndex] - 18446744069414584320);
}
else
{
directCache[directMapIndex] = (Convert.ToUInt64(i) << 32) + Convert.ToUInt64(stack[i]);
return stack[i];
}
}
set
{
stack[i] = value;
}
}
}
【问题讨论】:
-
我很难理解这个问题。缓存不存储偏移量中的数据;缓存将数据存储在数据块中。
标签: c# caching computer-architecture