It is not possible to force an array to use the L1 / L2 cache on most architectures; this is usually not required if you frequently access it, it is unlikely that it will be taken out of the cache.
Some architectures have a set of instructions that allows the processor to give a hint that a fast memory location will be necessary, so that it can start loading into the L1 / L2 log earlier - this is called prefetching, see for example the _mm_prefetch ( http: / /msdn.microsoft.com/en-us/library/84szxsww(v=vs.80).aspx ). However, this is unlikely to be needed if you are accessing a small array.
General tip: first make your data structures cache-efficient (put related data together, pack data, etc.), try reprogramming later if the profiler tells you that you still spend time skipping the cache, and you can Further do not improve the data structure.
source
share