On Thu, 5 Aug 1999, Richard MacLemale wrote:

> I have a question about RAM usage.
> I'm using a Macintosh G3 tower (300 MHz) with 128 meg RAM and virtual memory
> turned on, running OS 8.6.
> 
> I've got a stand-alone application created with MetaCard, and I've set the
> memory at:
> 8000K - minimum
> 8000K - preferred

That's pretty big, unless you're doing a lot of work with images,
AppleEvents, or HyperCard XCMDs (all of which require some memory be
allocated from the application heap).

> When I launch the app, then look at the "About this computer" window in the
> finder, the Mac says the program is allocated for 10.6 MB, though I only
> allocated 8000K.  Hmm.... it would be cool to hear a simply stated
> explanation of why this is, for my own info.  Other Mac applications don't
> seem to do this, or do they and I never noticed?

MetaCard uses Temporary Memory for storing most stack data.  Many
other apps do similar things (PhotoShop being one of the best known),
but since it's one of MacOSs dirty little secrets, few give any
indication that they're doing this.  One dead givaway is if the app's
install documentation says it conflicts with RamDoubler, which uses TM
too, and in incompatible ways.  MetaCard has a TMEM resource that you
can change to force MetaCard to stay in its own heap (partition), but
you have to increase the partition size if you do this.

> Next thing... in the same app, I load a big text file into RAM (about 1.2
> meg).  Suddenly the amount of RAM that the app takes up has ballooned from
> 10.6 MB to a whopping 21.3 MB!

Actually, you probably didn't just load it into RAM, you put it into a
field, which takes a lot more memory because it has to be broken into
a display list in that case.  It wouldn't do this if you just left it
into a variable.

>  Once the text file is cleared out of RAM,
> the RAM usage of the app goes to 20.1 MB, which makes sense... 21.3 - 20.1 =
> 1.2.  But what's with the rest of the RAM?  Why does it take 10 MB of extra
> RAM to read a 1.2 MB file into a global variable?  And why does MetaCard not
> give ALL of the RAM back after I clear the variable?

Most of this is just fragmentation.  That is, if you load a different
file, it won't grow any more.  A text file in a field is about the
worst case for this because lots of little blocks of memory need to be
allocated.  If you put a lot of data in variable, or load a large
image or sound file, all of the memory will be returned to the system
when you stop using it.

> I can surely break the text file up into smaller pieces to load and unload
> to avoid this problem, but there will be a speed hit.  If that's what it
> takes to keep the app within reasonable RAM usage, so be it... but I was
> just curious why this is, and what the deal is with how MetaCard asks for
> RAM on the Mac.  I realize I'm inviting a Master's Thesis discussion on RAM
> usage, but I'm just a poor ex-HyperCard user with no C++ background and I'm
> hoping someone can explain this to me so I can learn something new!

Using variables instead of fields should solve the growth problem.  As
for how MetaCard uses memory on the Mac, particularly the
fragmentation problem and the way it gets slower after you use it for
awhile, the important thing is to realize that it doesn't work all
that great now.  This is mostly because the memory management
libraries that Metrowerks ships with CodeWarrior are really lousy.
This is another area where major improvements will be made for the 2.3
release.
  Regards,
    Scott

> --Richard MacLemale
> www.coolclassroom.com 
> 

********************************************************
Scott Raney  [EMAIL PROTECTED]  http://www.metacard.com
MetaCard: You know, there's an easier way to do that...

Reply via email to