[comp.sys.mac.hypercard] Protection against memory limitation

GFX@PSUVM.BITNET (04/07/89)

I wrote a stack that works perfectly well on a Mac SE with 1 Meg.  Except
when people have CDEVS, Inits, cache settings or other similar things that
use a small fraction of memory.  Not enough to prevent the stack to open,
but when a script calls a paint tool for example, it will fail because there
is not enough memory left.

Other than warning users that they need a full meg to use the stack, what
could be done to 1) exit gracefully from a script if there is not enough
memory to execute, 2) detect memory shortage before it creates any problem.
Any other reaction, comment or suggestion?  Stephane

jdevoto@Apple.COM (Jeanne A. E. DeVoto) (04/08/89)

In article <80078GFX@PSUVM> GFX@PSUVM.BITNET writes:
>[...]when a script calls a paint tool for example, it will fail because there
>is not enough memory left.
>
>Other than warning users that they need a full meg to use the stack, what
>could be done to 1) exit gracefully from a script if there is not enough
>memory to execute, 2) detect memory shortage before it creates any problem.

There is an undocumented function "the heapSpace" that will return
(approximately) the number of bytes remaining in the application heap.
It's possible to do a little preflighting with this function to see
whether you are dangerously low on memory before doing a memory-
intensive operation.

As I mentioned, the function is undocumented and I don't know whether it
will be supported in the future. However, it has been present on all
versions of HyperCard so far.

jeanne a. e. devoto
jdevoto@apple.com

stm@apple.com (Steve Maller) (04/15/89)

In article <80078GFX@PSUVM> GFX@PSUVM.BITNET writes:
> Other than warning users that they need a full meg to use the stack, what
> could be done to 1) exit gracefully from a script if there is not enough
> memory to execute, 2) detect memory shortage before it creates any 
problem.
> Any other reaction, comment or suggestion? 

The HyperTalk function "the heapspace" returns the currently available 
amount of RAM. A little known (feature) of HyperCard is at every idle 
message, HyperCard checks to see that there is at least 32K of free 
memory. If it doesn't find it, it will complain and quit. But while a 
handler or an XCMD is executing, the amount of free memory can drop to 
zero.

Another recommendation is to make sure that you empty out any large 
HyperTalk globals that you allocate, such as text read in from a file.

Cheers,

       Steve Maller
       HyperCard Tools Engineer
       Apple Computer