[comp.sys.mac.programmer] CompactMem with MultiFinder partitions

jyp@wucs1.wustl.edu (Jerome Yvon Plun) (06/20/91)

If you have multiple applications being launched and terminating in random
order, you are bound to fragment your memory and not be able to obtain a 
application partition as big as the free memory.
If we were dealing with handle, a call to CompactMem would do the trick
(as in NewHandle or NewPtr).  Can a similar approach be undertaken by a
little program that would move an entire partition in memory and update
the value of A5 for that partition?

In fact, if there exists such a tool, I would be pleased to hear about it.
If not and the method I suggested is feasible, I might write a little
application implementing it.

Thanks.  Jerome 

Jerome Plun            []  Is it a crime to want something else?
jyp@wucs1.wustl.edu    []  Is it a crime to believe in something different?
Washington University  []  
St Louis, MO           []  "Smalltown England", New Model Army, Vengeance

dorner@pequod.cso.uiuc.edu (Steve Dorner) (06/20/91)

In article <1991Jun20.041856.5918@cec1.wustl.edu> jyp@wucs1.wustl.edu (Jerome Yvon Plun) writes:
>little program that would move an entire partition in memory and update
>the value of A5 for that partition?
>If not and the method I suggested is feasible, I might write a little
>application implementing it.

It's not feasible.  Every handle stored anywhere in the program would be
trash (think about it).

VM could conceivably be of help, but the Sys 7 implementation has the
charming feature of allowing FRAGMENTED virtual memory, a really stunning
concept.  If you have the MMU and the disk space, you can avoid the problem
by allocating a whopping big VM space, and then fragmentation, even if it
occurs, won't be a problem.
--
Steve Dorner, U of Illinois Computing Services Office
Internet: s-dorner@uiuc.edu  UUCP: uunet!uiucuxc!uiuc.edu!s-dorner

keith@Apple.COM (Keith Rollin) (06/21/91)

In article <1991Jun20.041856.5918@cec1.wustl.edu> jyp@wucs1.wustl.edu (Jerome Yvon Plun) writes:
>If you have multiple applications being launched and terminating in random
>order, you are bound to fragment your memory and not be able to obtain a 
>application partition as big as the free memory.
>If we were dealing with handle, a call to CompactMem would do the trick
>(as in NewHandle or NewPtr).  Can a similar approach be undertaken by a
>little program that would move an entire partition in memory and update
>the value of A5 for that partition?
>
>In fact, if there exists such a tool, I would be pleased to hear about it.
>If not and the method I suggested is feasible, I might write a little
>application implementing it.

The method you suggest is not feasible. There are non-relocatable blocks
in the application heap that you cannot move. For example, window
records are non-relocatable. You can't move these when you move the app
heap without updating all references to them. And there's no way you
can find all valid references to non-relocatable blocks.

Similarly, the master pointer blocks are non-relocatable, too.

-- 
------------------------------------------------------------------------------
Keith Rollin  ---  Apple Computer, Inc. 
INTERNET: keith@apple.com
    UUCP: {decwrl, hoptoad, nsc, sun, amdahl}!apple!keith
"But where the senses fail us, reason must step in."  - Galileo

ari@eleazar.dartmouth.edu (Ari Halberstadt) (06/22/91)

In article <1991Jun20.041856.5918@cec1.wustl.edu> jyp@wucs1.wustl.edu (Jerome Yvon Plun) writes:
>If you have multiple applications being launched and terminating in random
>order, you are bound to fragment your memory and not be able to obtain a 
>application partition as big as the free memory.
>If we were dealing with handle, a call to CompactMem would do the trick
>(as in NewHandle or NewPtr).  Can a similar approach be undertaken by a
>little program that would move an entire partition in memory and update
>the value of A5 for that partition?

It isn't sufficient to change A5, since it is likely that the application has
stored many addresses directly. For instance, taking the address of a function
doesn't return a reference off of A5, it returns a reference directly into the
jump table. And, of course, you'd have to change all the handles and pointers,
not to mention copies of the handles and pointers. No, it's not feasible to
actually move the application. But with virtual memory you could remap the
partition to somewhere else in physical memory. So you could move the
application, then use VM to make it think it was still in its old location,
simply by adding an offset to every address. I don't know if VM can be
controled to this extent by system 7.0 programmers. You might still have to
update operating system data structures (like the process manager), and this
is certainly very difficult without access to the source code.