[comp.lang.modula3] Allocation of objects in other than default heap ?

wyant@saber.com (02/14/91)

Here is a problem that I don't see how to solve
elegantly in M3. Suppose I want some objects to
be allocated from the process private heap, but some
I want allocated out of a heap existing in shared
memory (for instance I might be writing a fast local IPC
mechanism). I don't see any way in M3 of specifying which
heap should be used for a given allocation.  Is there
in fact a recommended way of doing this ? 

-- Geoff Wyant
wyant@saber.com

chased@rbbb.Eng.Sun.COM (David Chase) (02/14/91)

In article <9102131620.AA13112@riposte> saber.com!wyant@saber.com writes:

>... Suppose I want some objects to be allocated from the process
>private heap, but some I want allocated out of a heap existing in
>shared memory (for instance I might be writing a fast local IPC
>mechanism). I don't see any way in M3 of specifying which heap should
>be used for a given allocation.  Is there in fact a recommended way of
>doing this ?

I recommend you write an UNSAFE implementation for a SAFE interface
(if you can guarantee that it is truly safe).  You certainly shouldn't
expect to allocate TRACED objects from such a pool (especially for
your example), since doing so assumes a certain amount of clairvoyance
on the part of the author of the memory allocator and garbage
collector.  If you decide to allocate UNTRACED OBJECTS from that heap,
you'll need to get into bed with the compiler/run-time's
representation of TYPECODEs and method suites.  This is distinctly
non-portable, but so it goes.

I realize that this is probably not the helpful answer that you
wanted, but programing in unsafe/untraced M-3 is no worse than
programming in C, except that it is more verbose.  I can see where you
might wish for something like C++'s new-at-specified-location; perhaps
that should be considered.  However, be aware of the following
problems with such a scheme: (1) you need an interface that provides
the size for the object and for its hidden data structures (2) ynaitp
the align for the object etc (3) ynaitp the offset of the user-visible
pointer from the actual beginning of the allocated memory for the
object.  People who are paid to think about these things can no doubt
find other problems, and I wouldn't mind hearing about them.  For
UNSAFE code, it might be handy to be able get this function from a
some sort of optional standard interface.

Any thoughts from the committee on this?  It seems like such an
interface could be based on typecodes.  (Is this already in 1.6, which
I haven't bothered to fetch yet?  I'll go look, in my copious free
time.)

David Chase
Sun
  

muller@src.dec.com (Eric Muller) (02/14/91)

In article <7957@exodus.Eng.Sun.COM>, chased@rbbb.Eng.Sun.COM (David Chase) writes:
> It seems like such an
> interface could be based on typecodes.  (Is this already in 1.6, which
> I haven't bothered to fetch yet?  I'll go look, in my copious free
> time.)

Pickle has access to an interface in that style (RTHeapRep). While reading 
from a file, it will  rebuild pages that are acceptable to RTHeap and
declare these available when it is done.

-- 
Eric.