On 11/29/05 4:28 PM, Scott Fraser didst favor us with:
In the header "MacMemory.h", and in the documentation for
MemError, it
says in part:
"Instead of relying on MemError(), check before making a memory
request
that there is enough memory both to fulfill the request and to
support
essential operations."
My old app caches LOTS of data to improve performance, several
gigabytes worth at a time.
First, Apple discourage caching a lot of data. I don't know the
nature of
the data you're caching, but the problem with caching like this is
that once
your cached data is swapped out to disk, it's going to hurt
performance
instead of help it, and if you're caching this much it's invariably
going to
get swapped out to disk. So you want to be sure you're only caching
data if
it takes a long time to reproduce it. Nothing slows down my Mac
like VM
thrashing.
It rather depends on whether your data is expensive to calculate or
not. You do want to avoid page-outs though.
It is quite likely to (and does) run out of
VM, let alone real memory. However, it's very easy for me to release
these caches if I know to do so. What is the recommended way to
check
that there is "enough" memory left? The only obvious (or documented)
way of checking memory is to try to allocate some, which gets
expensive
if I have to allocate memory twice for each block of interest. Then
there is the old tried and true method of hanging on to a really
large
block, and freeing that before walking my cache, so I don't fail
while
doing even that.
There are some UNIX memory calls that other can tell you, or you
can search
the man pages. Nothing in the Mac Memory Manager is particularly
useful for
this as last time I hear things like MaxBlock just return a constant.
The Mac memory manager documentation is rather wildly out of date for
Mac OS X. You are probably best managing your cache as a fraction of
real memory (or a fraction of 4GB if real memory > 4GB).
If you want more detailed information about memory usage, look at
vm_statistics() and vm_region().
vm_statistics() allows you to get the paging situation of the machine
- you could start releasing your cached data if you start to get page-
outs.
vm_region() allows you to walk your address space looking for free
contigous blocks. It's normally not enough just to know the free
page count.
Steve Baxter
Software Development Manager
Improvision
+44-2476-692229
_______________________________________________
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