[comp.sys.mac.programmer] Shared addresses between applications with system 7

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

  I need to have a block of memory available to two applications running
concurrently (one of the applications doesn't know about the goodies of 
System 7 so I can't use either AppleEvents or raw PPC, and using a shared 
file is too slow).  
  I though of allocating a Ptr in one application, pass the address of the
Ptr to the other application (with the value of A5), and flip A5 whenever I
need to access the shared data.  This works fine if I assigne a constant to
the shared data, since the constant is not dependent on A5.  But if I want to
copy a variable from one application's A5 world into the shared data from the
other application's A5 world, I need to write a little routine in assembly
that copies the value of the source into a register (say d0), changes A5, and
writes d0 into the destination variable.  Doing that for a buffer of data is
cumbersome.
  
  So, I would like to know if it possible to convert an "Address Register
Indirect with Displacement" (i.e. A5 + offset) into an absolute address for
a global variable, thus making that variable independent of what application
is being executed.

  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

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

I solved my problem of shared variables between applications by using 
inline assembly code within my C code.  

If anybody is interested by this code,, send me email.

Sorry for the bandwidth used for these two postings but I _HATE_ assembly
code.

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

russotto@eng.umd.edu (Matthew T. Russotto) (06/13/91)

In article <1991Jun12.204031.11225@cec1.wustl.edu> jyp@wucs1.wustl.edu (Jerome Yvon Plun) writes:
>
>  I need to have a block of memory available to two applications running
>concurrently (one of the applications doesn't know about the goodies of 
>System 7 so I can't use either AppleEvents or raw PPC, and using a shared 
>file is too slow).  

I'm not sure what the problem here is.  Assuming you can pass a pointer from
one application to another, have one program do a NewPtr, pass the pointer
(which is an absolute pointer) to the other program.  Then both programs can
access that area of memory (which actually exists in the first application's
heap, but that is relatively unimportant...)
--
Matthew T. Russotto	russotto@eng.umd.edu	russotto@wam.umd.edu
     .sig under construction, like the rest of this campus.

zben@ni.umd.edu (Ben Cranston) (06/20/91)

In article <1991Jun13.145629.14699@eng.umd.edu> russotto@eng.umd.edu
(Matthew T. Russotto) writes:

> ...  Assuming you can pass a pointer from
> one application to another, have one program do a NewPtr, pass the pointer
> (which is an absolute pointer) to the other program.  Then both programs can
> access that area of memory (which actually exists in the first application's
> heap, but that is relatively unimportant...)

If you have virtual memory turned on this may not work, as the first
application (and its heap) may get swapped while the second application
is running.  Maybe the first application can "lock" that area of memory
down somehow (I haven't gotten that far in reading VI yet!!!) but the
better part of valor might be to allocate in the System heap which is
never subject to swapping...

Edward.Rice@p4214.f421.n109.z1.FidoNet.Org (Edward Rice) (06/20/91)

Re:
     the better part of valor might be to allocate in the System heap
     which is never subject to swapping...

Allocate AND LOCK in the system heap, yes.

 * Origin: "It's still in beta testing," Tom said Pointedly. (1:109/421.4214)

davoli@natinst.com (Russell Davoli) (06/21/91)

In article <677390460.2@blkcat.FidoNet>, Edward.Rice@p4214.f421.n109.z1.FidoNet.Org (Edward Rice) writes:
> Re:
>      the better part of valor might be to allocate in the System heap
>      which is never subject to swapping...
> 
> Allocate AND LOCK in the system heap, yes.
> 
>  * Origin: "It's still in beta testing," Tom said Pointedly. (1:109/421.4214)

I assume you meant allocate and HLock, or simply allocate with NewPtr.
According to the documentation, all of the system heap is locked in memory,
which means that it can't be swapped or even moved around in physical memory.

Seems to me that simply allocating in the application heap of one of the
applications would work, too, as long as a HoldMemory call is made before
passing the virtual address to the other application.  The way I understand
Apple's virtual memory system, applications don't have independent virtual
address spaces and wind up using partitions of the virtual address space.
The application that receives the pointer should be able to look into the
other's address space.

I don't claim to be an expert on Apple's implementation, so please correct
me if I'm wrong.

--------------------------------------------------------------------------
Russell Davoli (davoli@natinst.com)
Software Eng.
National Instruments Corp.