Hi,
I have a question about mmap(), hope someone can clarify for me. As I know, mmap() maps the whole file into memory, so OS can access the source file directly from memory. However there should be a restriction to memory size on the embedded system.
In my test, I compile madplay with mmap supported, and then play a mp3 file of 43MB, and it plays well. But my question is I only get 32MB SDRAM on my development board. It seems that the memory size is not large enough to store all the data. How does mmap() work?
Besides, I want to implement the fast forward/rewind function. But it is a little slow to rewind, because it needs to search the location from the first frame, if mmap() isn't enabled. (Maybe there are other better methods, but I don't know...) If mmap() works, then it should be faster than without mmap(), shouldn't it?
Sorry for any unclear expression. Thanks for help.
Regards, Hank
On Thu, 27 Nov 2003 14:57:11 +0800, hank.jan@billionton.com.tw wrote:
I have a question about mmap(), hope someone can clarify for me. As I know, mmap() maps the whole file into memory, so OS can access the source file directly from memory. However there should be a restriction to memory size on the embedded system.
In my test, I compile madplay with mmap supported, and then play a mp3 file of 43MB, and it plays well. But my question is I only get 32MB SDRAM on my development board. It seems that the memory size is not large enough to store all the data. How does mmap() work?
mmap() maps pages of memory to correspond to the file, but it doesn't actually load the file into memory. The file is loaded on demand. When you access one of the mapped pages, the OS loads the correct part of the file into memory. The effect is similar to virtual memory, where pages are swapped to and from the disk when they're needed.
Thus, if you're using a 32 bit CPU, you may be able to map up to 4 GB with mmap(), even if you only have 32 MB of RAM. Adding more RAM will allow you to keep more of the file in memory at once, so random access will be faster, but it doesn't affect the size of the file you can map.