cache

Started by
1 comment, last by WizHarDx 22 years, 5 months ago
thanx guys for answering my other question. But I have one more question. How do you access || use the cache in C++. Or do I need to learn assembly ? thanx in advance WizHarD
who is it that keeps on nicking WizHarD name !! :P
Advertisement
You don''t - the cache is a hardware thing and is totally transparent to software. Even the OS doesn''t know anything about the cache.

Now, what you can do, since you know how the cache works (well, theoretically) is optimize your code to take advantage of it. I''m not much of an assembly freak, so I don''t know half the tricks you can do, but things like reading contiguous blocks of memory and not random locations all over the place will make good use of the cache. Also, keeping your memory accesses small (that is, only using a 1KB or 4KB or 8KB block of memory) will be fast, since the whole block can be kept in the cache.

codeka.com - Just click it.
There are some assembly instructions that you can use to control the cache on newer processors. You can for example prefetch a memory location to the cache, write back the data in the cache etc.

A good optimizing compiler will insert instructions like this for you, so there is normally little reason to hand-optimize code only for this purpose.

If you''re interested you should take a look at the Intel IA-32 Manual.

This topic is closed to new replies.

Advertisement