Jump to content
  • Advertisement
Sign in to follow this  

Disable cache on an array?

This topic is 4772 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all, I have a large array (1.5 megs) that I access fairly regularly in my program, but its access time really isn't an issue. However, because it is so big, it seems to be filling up my cache (256k) and causing a lot of cache misses for the rest of the program, which really slows things down. So, my question is, is there any way I can instruct the computer to not cache a section of ram? (this is in C++ on WindowsXP, gcc 3.3.1) Thanks.

Share this post


Link to post
Share on other sites
Advertisement
Use VirtualAlloc or VirtualAllocEx to allocate your memory and pass it the PAGE_NOCACHE flag, along with the other relevant settings.

Share this post


Link to post
Share on other sites
VirtualAlloc doesn't accept the PAGE_NOCACHE flag, except on Windows CE where it's mostly useful for device drivers and the like anyway.

There's not any way to disable the CPU cache for regions of memory. How do you know it's filling up the cache anyway?

Share this post


Link to post
Share on other sites
Quote:
Original post by Dean Harding
VirtualAlloc doesn't accept the PAGE_NOCACHE flag, except on Windows CE where it's mostly useful for device drivers and the like anyway.

There's not any way to disable the CPU cache for regions of memory. How do you know it's filling up the cache anyway?


Actually, the very page you link to says that it can be used. And yes it is usually only useful for device drivers, that however does not mean it is never useful for anything other than that.

Also, it is absolutely possible to disable the hardware cache when reading or writing to a region of memory.

Share this post


Link to post
Share on other sites
Quote:
Original post by Mastaba
Actually, the very page you link to says that it can be used. And yes it is usually only useful for device drivers, that however does not mean it is never useful for anything other than that.

Also, it is absolutely possible to disable the hardware cache when reading or writing to a region of memory.


Oh you're right! I only saw it on the CE documentation, didn't read that page too much, heh. Still, I wouldn't recommend doing it...

Share this post


Link to post
Share on other sites
How much RAM do you have? I think you'll find that stuff is getting paged to/from disk if you have an array that big. The performance hit from that would probably pale in comparison to pushing some stuff out of the cache.

Besides, you said it's accessing that array fairly regularly. How can you possibly know that what it's already doing isn't way faster than your idea? You're simply trading one cache miss for another, and that I doubt the cache is stupid enough to page out any more-frequently-used part before the lesser-used part.

I'd recommend tackling the problem from a different angle. Is your 1.5MB array vertex data by chance? If so, are you using doubles when you could use floats, or using floats where you could use custom 16-bit compressed floats. If you're already doing that then you could store 8-bit deltas for every 2nd vertex etc...
Even decompression from RAM -> RAM is usually much faster than reading from HD. If I were you, I profile to find the bottleneck(s), then probably concentrate on doing everything possible to reduce the size of that array, if it is a bottleneck.

Share this post


Link to post
Share on other sites
Stuff shouldn't get paged to/from disk from using a 1.5meg array.. ;]
...but, shrinking it is always good.

Have you tried using the "volatile" keyword?
It _should_ keep it from getting cached.

But like iMalc said (shortened down ;]): the compiler is quite good at optimizing stuff.. ;]

Good luck!

Share this post


Link to post
Share on other sites
Quote:
Original post by gulgi
Have you tried using the "volatile" keyword?
It _should_ keep it from getting cached.

No it won't...that's purely a compiler setting. Without the volatile keyword, the compiler might store it in a register or something of that nature. From your program's point of view, the cache is completely transparent.

CM

Share this post


Link to post
Share on other sites
Quote:
Original post by gulgi
Stuff shouldn't get paged to/from disk from using a 1.5meg array.. ;]
...but, shrinking it is always good.
Oh crap, I was thinking of 1.5GB! Geez I even wrote MB myself though.
My mistake, sorry!!!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!