Is there a way to force a variable to be stored in the cache in C?

前端 未结 5 825
误落风尘
误落风尘 2021-02-05 23:55

I just had a phone interview where I was asked this question. I am aware of ways to store in register or heap or stack, but cache specifically?

5条回答
  •  终归单人心
    2021-02-06 00:25

    It depends on the platform, so if you were speaking to a company targetting current generation consoles, you would need to know the PowerPC data cache intrinsics/instructions. On various platforms, you would also need to know the false sharing rules. Also, you can't cache from memory marked explicitly as uncached.

    Without more context about the actual job or company or question, this would probably be best answered by talking about what not to do to keep memory references in the data cache.

提交回复
热议问题