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 (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to