How to flush cache?

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 memory cache. Also, it is a requirement for my project which involves calculating the time taken for my logic, therefore I need to flush the cache. Can someone be kind enough to help?
What do you mean by "memory cache", and what do you mean by "flush"? These terms are heavily contextual.
By memory cache I mean the data cache. And by flush I mean that I want to clear out the contents of the cache
I'm going to assume that you mean a known section of memory that you have a pointer to, and that you know the size of the memory.

You cannot "clear out" memory. All you can do is put a new value in it. Commonly in C and C++ this is done using memset. Here is how to set some memory to zero.

memset (pointerToMemory, 0, sizeOfMemory);
I mean the data cache

All caches store data, so that's not saying much.
Do you mean the page cache? Or the CPU caches? Or...?
Topic archived. No new replies allowed.