[comp.sys.mac.programmer] Why does this work?

milikich@iccgcc.decnet.ab.com (Mike Milikich, Allen-Bradley Company) (01/23/91)

	I guess the MoreMasters thread isn't dead yet!

	As part of a data acquisition app in Think C, I set up a list of blocks
of memory linked by their handles. Without ever calling MoreMasters (), I link
up 100 of these things. I did this on purpose at first to make sure I knew what
the MoreMasters () call would do. Obviously, I don't - the things works fine.
Why can I get 100 handles with calls to NewHandle () ? If it matters, this is
on a IIcx with 8 meg.

Mike :

--------------------------------------------------------------------------------
| milikich%iccgcc.decnet@consrt.rok.com |"Quick to anger, slow to understand;  |
| allen-bradley company                 | ignorance and prejudice and fear     |
| 747 alpha drive                       | walk hand in hand."                  |
| highland heights, ohio  44143         |--------------------------------------|
| (216) 646-3406  FAX : (216) 646-4343  | This is an official disclaimer.      |
--------------------------------------------------------------------------------

stevec@Apple.COM (Steve Christensen) (01/23/91)

milikich@iccgcc.decnet.ab.com (Mike Milikich, Allen-Bradley Company) writes:
>
>	I guess the MoreMasters thread isn't dead yet!
>
>	As part of a data acquisition app in Think C, I set up a list of blocks
>of memory linked by their handles. Without ever calling MoreMasters (), I link
>up 100 of these things. I did this on purpose at first to make sure I knew what
>the MoreMasters () call would do. Obviously, I don't - the things works fine.
>Why can I get 100 handles with calls to NewHandle () ? If it matters, this is
>on a IIcx with 8 meg.

You never *have* to call MoreMasters(), but it's provided for more intelligent
heap management.  If you call NewHandle() and there are no more free master
pointers, then MoreMasters will be called to create a new MP block.  Being
that the MP block is non-relocatable, it will be created as close to the
beginning of the heap as possible--which may not be that close if a bunch of
other blocks (non-relocatable and/or locked relocatable) already exist.  If
some of those relocatable blocks are unlocked and move, then the MP block
becomes an island in the heap, effectively fragmenting it into two pieces.
If you call MoreMasters one or more times when your program first starts up,
then the MP blocks will be created very close to the beginning of the heap,
reducing the chances of heap fragmentation...

steve

-- 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  Steve Christensen	|  Apple Computer, Inc.		|  Disclaimer:
			|  20525 Mariani Ave, MS-81CS	|   the above may be
  stevec@apple.com	|  Cupertino, CA  95014		|   a lie...or not.

hairston@henry.ece.cmu.edu (David Hairston) (01/23/91)

[milikich@iccgcc.decnet.ab.com (Mike Milikich, Allen-Bradley Company) writes:]
[] As part of a data acquisition app in Think C, I set up a list of blocks
[] of memory linked by their handles. Without ever calling MoreMasters (), I
[] link up 100 of these things. I did this on purpose at first to make sure I
[] knew what the MoreMasters () call would do. Obviously, I don't - the thing
[] works fine.
[]
[] Why can I get 100 handles with calls to NewHandle () ? [...]

as i understand it, you never _have_ to call MoreMasters() since the
memory manager will allocate (if possible) a new block of master
pointers as needed.  the reason you _want_ to do this is to keep
your memory profile optimized (if that's a concern).  remember that
each newly allocated block is non-relocatable, so if you know in
advance what you'll need (plus an extra margin) you can pre-allocate
this space and keep it out of the way.

  -dave-  
hairston@henry.ece.cmu.edu

egw.weakm@p3.lanl.gov (Eric Wasserman) (02/13/91)

If there aren't enough master pointers around the Memory
Manager will call MoreMasters itself as it needs them.  The
problem is that blocks of master pointers are
non-relocatable so if MoreMasters gets called by the Memory
Manager deep into your code you'll probably wind up with a
nasty non-relocatable block in the middle of your heap.


Eric
egw.weakm@p3.lanl.gov