4

Can I use namespace System.Runtime.Caching in order to modify the properties and values of CPU Cache L1, L2 and L3?

msdn.microsoft.com told me the namespace allows create new cache storage in windows like a virtual RAM.

But, i wanna program with Cache which is included by CPU. Can you tell me how to do that?

Thanks for solutions!

1 Answers1

5

System.Runtime.Caching provides access to high level cache facilities, generally on regular RAM with key-value pairs. (There are more use cases beyond that.) Like you mentioned, MSDN says:

You can create custom caching providers. For example, instead of using the default in-memory cache engine, you can create custom providers that store cache data in databases, in custom objects, or in the file system.

But CPU cache is a low level memory that is used automatically with the CPU itself to reduce a trip to RAM; So it is not actually meant to be modified by external applications.

For example, L1 instruction cache is physically next to the processing core and it stores machine code instructions and .NET applications are not even stored as a machine code before they are run by .NET Framework itself (or ngen) which makes low level operations even more harder.

CPU cache

But this doesn't mean that they can't be affected by your code. You can write efficient code that makes CPU to use its caches in an elegant way. For more information, see: How does one write code that best utilizes the CPU cache to improve performance?

Community
  • 1
  • 1
Furkan Omay
  • 1,047
  • 1
  • 11
  • 22