Memory management and mmap
Memory management and mmap
- Subject: Memory management and mmap
- From: "Dave Keck" <email@hidden>
- Date: Tue, 2 Sep 2008 05:58:59 -1000
Hello!
I'm developing an app that must handle thousands of image thumbnails. Obviously I need some method of handling all these thumbnails in memory. I'm building this app for Tiger so I can't use any spiffy Leopard features.
It is my understanding that 32-bit apps cannot address more than 4 GB of virtual memory. Right now our app simply keeps these thumbnails in a backing store file, and as thumbnails are displayed, their respective chunk is mmap'd into memory from the backing store file. (We're mmap'ing instead of simply reading from the file to decrease loading times, so the thumbnail data is read lazily on a need basis). Here lies our problem: if too many photos are imported, there won't be enough virtual memory to handle all the thumbnail data, and the app will crash.
So I need a way to cap how much of the thumbnail backing store file is kept in memory. My main issue is what happens when a chunk that is in-use by an object is munmap'd to make space for new data (and perhaps some different thumbnail data is re-mmap'd into the same location). I was thinking I could implement some sort of signal handler that gets called whenever a chunk of mmap'd memory was going to be read, and I could check this chunk against a list of recently-modified chunks of virtual memory. If it hasn't been changed, then it can simply be read. If it has changed, I must re-mmap it into memory and read it again, marking the previous occupant of that space as changed. I realize this is much the same way as the virtual memory system works, so perhaps there is already some solution available that I could take advantage of? Or perhaps someone has a better memory management system in mind?
Thank you!
David
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden