I would normally agree. However this is a *specific* case where it would be quite nice to do this. In this *specific* case, there is no 64-bit option for me nor is worrying about the VM an option either. The amount of memory is pretty small anyway both ways (allocation and available).

Let me put it another way. I'd like to learn how to do this in OS X notwithstanding all the exceptionally valid points you've made. I understand its possible that I can't do this due to permissions or other reasons. But if I can, it would be nice. If I can't, I'd just like to know.

One fun thing to do with this is to simply do an Instrument's like log file showing free physical RAM of a machine over time.

On Aug 27, 2008, at 11:48 PM, Bill Bumgarner wrote:

On Aug 27, 2008, at 9:31 PM, Alex Kac wrote:
I need to check for free RAM before performing a specific operation. I've Googled and checked in the docs and I suspect its my terminology that's just out of whack.

So what is the best way to find out how much available RAM is available in a Cocoa app?

That question isn't entirely relevant to coding on a multi-user, multi-processing, VM'ing system.

It is also a question that will change rapidly due to circumstances well beyond your application's control.

If you poke about the various mach_* APIs, you can grab some relevant statistics such as paging event rate or some stats on current memory usage, but it will largely just be hints.

In general, you should allocate what you need, use it as you see fit, and then release it when done. You generally use malloc() throughout, but vm_allocate() and friends can be used for more specialized memory management needs.

The real questions is why do you think you need to know how much RAM is available before doing something?

Are you looking for contiguous address space? You'll probably want to go 64 bit, then, as 32 bit will have much less than 4GB of contiguous address space available.

Are you looking to avoid paging? If so, you are kind of out of luck. There is nothing that can prevent another app from deciding to do something similar and forcing the system into paging death.

Something else?

b.bum


Alex Kac - President and Founder
Web Information Solutions, Inc.

"Forgiveness is not an occasional act: it is a permanent attitude."
-- Dr. Martin Luther King




_______________________________________________

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 [EMAIL PROTECTED]

Reply via email to