Windows - How to drop the HDD cache

I'm writing a program which scans the HDD with a recursive FindFirstFile etc. Works great but the first time I run it after reboot, it takes about 75 seconds, the second time about 3 seconds and subsequently.

Clearly the info is getting cached either in the HDD memory or in Windows cache.

Is there any way of clearing this so I can replicate the slowness of the first time run, without the need to reboot ?

Programming or any other solution would be fine.

thanks
LVL 8
plqAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

plqAuthor Commented:
Thanks, I can see some caching info in that link, but this relates to CreateFile and not FindFirstFile, there is no option to specify these flags in FindFirstFile ?

Please let me know what you had in mind.

thanks again
0
jkrCommented:
Is there a particular reason why you want this to be slower?
0
OWASP: Avoiding Hacker Tricks

Learn to build secure applications from the mindset of the hacker and avoid being exploited.

plqAuthor Commented:
Yes, the software will normally run one time on the end clients, sometimes as part of bootup, but usually from a sysadmin's scheduled task. So I have to optimise it for uncached behaviour. To do the optimisation, I need to be able to reproduce the same conditions as just after a reboot. But a reboot of a box takes quite some time, so I'm hoping for a solution like a dos command which clears any cache, or a way of calling findfirstfile that stops it caching in the first place.

Just to clarify this is purely for my debug environment so I can replicate the slowness of running the software against a booted up machine.

thanks
0
jkrCommented:
OK, this is just an idea, though it could work: Create a network share for your partition and access it via '\\machine\sharename' - this might circumvent the cache.
0
plqAuthor Commented:
Thanks, but in this case it would take quite a bit of development effort to do that.

I guess no might be a valid answer here, but lets just see what other ideas come in.. thanks
0
jkrCommented:
>>in this case it would take quite a bit of development effort to do that.

I hope not. It mainly would boil down to

net share add Testing=c:\
net use x: \\.\Testing

and use 'x:' as your root directory.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
plqAuthor Commented:
The program isn't just a root scan of all folders, it scans for specific folders via the registry, shortcuts, key areas, etcm and then deep scans those to specific levels depending on context. So there's not a single root. I'll see if I can fudge a way around it, but I suspect I need some "cache killer" program that fools the OS and disks into losing any cache !  
0
LMiller7Commented:
The system cache in Windows is controlled by registry entries which are not well documented. One program that claims to be able to control the cache is Cacheman:
http://cacheman.outertech.com/index.php?_charisma_page=product&id=2

I have not used this program so I don't know anything more than is on the website. I cannot verify it's claims and merely suggest it as a possibility.

Note that I normally do not recommend programs of this type as they usually do more harm than good. But it may do what you want.

0
plqAuthor Commented:
I never found a solution, so ended up spending days rebooting it instead. THe shares stuff still got cached

thanks for helping anyway. I guess it just might not be possible to remove cached information.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.