开发者

How to read file with no-cache in Android?

I am working on a test application on Android platform. Test the write/read speed to the sdcard. I write in C language with NDK interface.

First I write a for-loop to create 256 files with 512 random bytes in each. This part works fine. I open file with flag O_CREAT|O_WRONLY|O_SYNC and mode 0666. After call write, I do sync() to make sure the data is written on the card.

Then I write another 2-level for-loop to read these file to test speed. I use O_RDWR|O_SYNC to open the file. Then call read().

Here is the thing: If it is the first time I run the read part. The first loop to read take more time than the after. I'm sure it is because after the first loop, program read the cache not the real physical card.

I've tried O_DIRECT flag to read. But it error with EINVAL. In the man page for open, it says maybe it is because of this function not implement by the platform.

Do you have any idea on how to 开发者_开发技巧read with no-cache in Android?


You may need a rooted phone to disable operating-system-level caching.

https://web.archive.org/web/20120531024443/http://wiki.cyanogenmod.com/index.php?title=SDCardSpeedTests

That also takes care to do operations large enough to overwhelm any on-card buffers.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜