Re: Getting notified when memory gets tight
Re: Getting notified when memory gets tight
- Subject: Re: Getting notified when memory gets tight
- From: Graham Cox <email@hidden>
- Date: Sat, 3 Jul 2010 11:37:40 +1000
On 03/07/2010, at 9:47 AM, Jens Alfke wrote:
>
> On Jul 2, 2010, at 12:14 AM, Graham Cox wrote:
>
>> I'd like to be able to do something a bit like it on 10.5. Is there a notification or other callback I can use to get notified when the system is running low on memory for my app, to give it an opportunity to discard stuff before it starts paging memory out?
>
> On a Modern OS™ it’s not easy to say when the system’s running low on memory, because there’s physical RAM, and there’s address space, and the pages in address space can be clean or dirty, or mapped from a file, and so forth. And all of that stuff is shareable between processes.
>
> What NSCache does, I believe, is use the vm_allocate() system call to allocate address space that’s marked as being purgeable: its pages won’t get written to backing store, they just get thrown away. You have to make calls to lock and unlock purgeable memory so it won’t get thrown away while you’re using it.
>
> There’s some info about vm_allocate here, although it doesn’t talk about the purgeable mode. IIRC, the header file does, though.
> http://developer.apple.com/mac/library/documentation/Performance/Conceptual/ManagingMemory/Articles/MemoryAlloc.html
>
> —Jens
Thanks Jens, I'll look into it.
It might not be worth it, as we are trying to encourage users to move to 10.6. My 10.5 cache already limits the number of cached items and discards the least recently used ones to stay within the limit - that might be enough especially as previously we just cached these items in a NSMutableDictionary and it was never purged.
But now I've seen NSCache in action, it's a nice addition to the arsenal - pity it wasn't thought of earlier!
--Graham
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden