[comp.sys.mac.programmer] Expanding System Heap

jskuskin@eleazar.dartmouth.edu (Jeffrey Kuskin) (04/12/89)

    I am in the process of writing an interrupt-handler which will
install itself into the SYSTEM heap.  The handler itself is not large
(300 bytes or so), but it requires a large data buffer (approx. 40K).
All this is for a 1 Meg SE, by the way.

    The problem:  The system heap does not have enough free space
        for me to be able to allocate a 40K block.  I have so far
        circumvented this problem by allocating a smaller buffer
        and filling/emptying it several times.  However, I would
        like to be able to use a full, 40K buffer.

    The questions:
        1)  Is there a way to increase the size of the system heap
            at run time?  That is, could the appication which installs
            the interrupt handler increase the size of the system heap?

        2)  If it turns out to be unfeasible to increase the size
            of the system heap, is there any danger in using most
            (say, 90%) of whatever free space remains in it?
            How well do the System/Finder cope with low-memory
            situations in the system heap?

    Thanks for any help.  Please E-mail responses.

    --  Jeff Kuskin, Dartmouth College

    EMAIL:  jskuskin@eleazar.dartmouth.edu

oster@dewey.soe.berkeley.edu (David Phillip Oster) (04/12/89)

In article <13002@dartvax.Dartmouth.EDU> jskuskin@eleazar.dartmouth.edu (Jeffrey Kuskin) writes:
>    I am in the process of writing an interrupt-handler which will
>install itself into the SYSTEM heap.  The handler itself is not large
>(300 bytes or so), but it requires a large data buffer (approx. 40K).
>All this is for a 1 Meg SE, by the way.
The Startup Manager chapter of Inside mac Vol 5. describes a mechanism for
making the system grow the system heap for your INIT before it runs it.
You paste a resource into your INIT that contains a LongInt of how much
space you need for you INIT to run. INIT 31 will grow the system heap
before running the INIT.

kent@lloyd.camex.uucp (Kent Borg) (04/12/89)

In article <13002@dartvax.Dartmouth.EDU> jskuskin@eleazar.dartmouth.edu (Jeffrey Kuskin) writes:
>
>    I am in the process of writing an interrupt-handler which will
>install itself into the SYSTEM heap.  The handler itself is not large
>(300 bytes or so), but it requires a large data buffer (approx. 40K).
>All this is for a 1 Meg SE, by the way.
>
>    The problem:  The system heap does not have enough free space
>        for me to be able to allocate a 40K block.  I have so far
>        circumvented this problem by allocating a smaller buffer
>        and filling/emptying it several times.  However, I would
>        like to be able to use a full, 40K buffer.

There are two places to stash things at startup: 1) In the system heap
as you are now, and 2) by moving down BufPtr and using the space
between the old and new locations.

#1 you are doing now, and I just saw a posting go by saying how to
expand the heap at init time.  Try that.

I have heard that there are times when you can't do that in smaller
machines (can't remember the details, maybe it's no longer true).  In
that case you might move BufPtr down.  Moving BufPtr has the
unfortunate side effect of being rather permanent, there really is no
way to give that memory back without rebooting.

Kent Borg
kent@lloyd.uucp
or
...!hscfvax!lloyd!kent

austing@Apple.COM (Glenn L. Austin) (04/13/89)

In article <13002@dartvax.Dartmouth.EDU> jskuskin@eleazar.dartmouth.edu (Jeffrey Kuskin) writes:
>    The problem:  The system heap does not have enough free space
>        for me to be able to allocate a 40K block.  I have so far
>        circumvented this problem by allocating a smaller buffer
>        and filling/emptying it several times.  However, I would
>        like to be able to use a full, 40K buffer.
>
>    The questions:
>        1)  Is there a way to increase the size of the system heap
>            at run time?  That is, could the appication which installs
>            the interrupt handler increase the size of the system heap?

This may be more suitable to network response.

If you are loading as an INIT, you can use the sysz resource (a longint)
to request that the System heap be enlarged by that amount, or you can grow
the System heap yourself (as documented in IM 4).  If you are doing this for
an application, you don't really need to grow the system heap.  Allocate your
space in the application heap, since it is a "one program only" situation.


-----------------------------------------------------------------------------
| Glenn L. Austin             | The nice thing about standards is that      | 
| Apple Computer, Inc.        | there are so many of them to choose from.   | 
| Internet: austing@apple.com |       -Andrew S. Tanenbaum                  |
-----------------------------------------------------------------------------
| All opinions stated above are mine -- who else would want them?           |
-----------------------------------------------------------------------------

mkg@lzsc.ATT.COM (Marsh Gosnell) (04/13/89)

In article <28844@apple.Apple.COM>, austing@Apple.COM (Glenn L. Austin) writes:
> If you are loading as an INIT, you can use the sysz resource (a longint)
> to request that the System heap be enlarged by that amount, ...

The sysz mechanism ONLY guarantees that the free space in the system heap
equals (or exceeds) your request.  It will increases the size of the system
heap by the amount needed to meet your request-not by the amount of your
request.  If you ask for space you don't use, that free space will count
towards the next INIT's sysz request.

If you want to have free space available later, you must allocate
something into that space to keep it from being reused by another INIT.
  Marsh Gosnell