开发者

Using a memory mapped file as a swap file?

I'm working in Android where memory is limited and there is no swap file like feature. I've read that people have implemented swap file like functionality using memory mapped files in their apps but I don't understand how this would work. Does anyone know?

I think the general idea is that, if my program wanted to use an int array that was the size of say 20Mb, I开发者_如何学编程 could create the data for this array in a 20Mb file and then use the memory mapped file feature to transparently bring into memory the parts of the file I current need to read and write to. The crucial element is that, although I have 20Mb of space to read/write to, only a small fraction of this is ever in memory at a time (Android apps are limited to ~24Mb of memory).

I'd prefer to work in Java for this but a C solution would also work.

Edit: This memory mapped file trick is mentioned here but I don't understand how it would work http://grammerjack.blogspot.com/2009/10/gles-quake-port-of-quake-to-android.html


In Java, use java.nio.MappedByteBuffer.

In C, use the POSIX function mmap(). It works on Android fine.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜