I am writing a C program in which I need to flush my memory. I would like know if there is any UNIX system command to flush the CPU cache.
This is a requirement for my project which involves calculating the time taken for my logic.
I have read about the cacheflush(char *s, int a, int b)
function but I am not sure as to whether it will be suitable and what to pass in the parameters.
If you turn off the PC and unplug the power (to know for sure it's off) all cache/RAM in the system (including that in the CPU, GPU, memory, storage drives, etc.) is cleared.
In all the Linux systems we have three options to clear cache without interrupting any services or processes. Now to set run permission, to clear ram cache, you have to call the script whenever required, setting a cron to clear RAM caches every day for 3 hours.
cacheflush() flushes the contents of the indicated cache(s) for the user addresses in the range addr to (addr+nbytes-1). cache may be one of: ICACHE Flush the instruction cache. DCACHE Write back to memory and invalidate the affected valid cache lines.
I take it you mean "CPU cache", not memory cache
The link above is good: the suggestion "write a lot of data via CPU" is not Windows specific
Here's another variation on the same theme:
Here's an article about Linux and CPU cache:
NOTE:
At this (very, very low) level, "Linux" != "Unix"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With