Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Carbon-dev Digest, Vol 2, Issue 83




On Jan 29, 2005, at 7:42 PM, Laurence Harris, Aandi, and Skip wrote:


Now I need a way to be able to check if I have sufficient memory after my allocations so that the Mac can actually keep running without crashing in calls such as DrawPicture.

That's basically what I said, though it's not quite that simple. Can your
application have multiple windows? Can they be any size? Could the user open
a save file dialog when memory use is high? Point is, it's very hard to
predict how much memory the system will need at various times.


There's another VM issue that can bite you. When you allocate memory, say
with NewHandle(), the system doesn't really do much more than make sure
there's room within your 4GB space. It does not, as you might suppose,
verify that there's sufficient space on disk for VM to actually provide all
the memory you requested. For example, suppose you call NewHandle(.9GB).
Suppose further that this is allowable given the available space in your
memory space. But suppose there is only .4GB left on the hard drive for VM
to grow swap files. Uh oh. The Memory Manager will let you allocate the
handle, but if you try to actually write to all of it, your Mac will fall
down. And Apple can't fully address this problem. To do that, the VM system
would have to reserve 4BG of disk space for every running application, and
that's just not feasible. I have ten applications running at the moment, and
that would mean the system had to reserve 40GB of my 60GB disk just for VM.



One possible strategy that I am working on is this. I pick a buffer size, some guestimate as to what the application is going to need to keep running. I haven't come up with a real value for this yet, but in my tests, I am just grabbing a 64 MByte chunk.


Just prior to doing any operation that could allocate a huge amount of memory and fail, I first attempt to grab a 64 MByte chunk of RAM, as a contingency buffer. Allocate it, do nothing with it, except hold onto it. I then proceed with my regular memory allocations. IF the allocations fail, they roll back. IF they succeed, great. In either case, I then let go of the contingency block, and cross my fingers that there is enough memory available for the application to keep running nicely and not choke somewhere in which I have no control. So essentially all big consumers of memory in my application would be framed by a grab at a contingency buffer, and a release of it afterwards. IF you can't get the buffer, you can't proceed with the requested operation.

Anyone see any problems with such a strategy? And does anyone have any suggestions as to a good strategy for figuring out the size of this "set-aside" memory?

Skip


_______________________________________________ Do not post admin requests to the list. They will be ignored. Carbon-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/carbon-dev/email@hidden

This email sent to email@hidden


Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.