[M3devel] returning record by value vs. by ref?
Tony Hosking
hosking at cs.purdue.edu
Sat Dec 1 21:23:19 CET 2007
Correct! Anytime you create an l-value pointer.
On Dec 1, 2007, at 2:31 PM, Rodney M. Bates wrote:
> Tony Hosking wrote:
>> I am assuming 's' here is an open array (REF ARRAY OF item) in
>> which case it is allocated in the GC'd heap. There is certainly
>> no way of safely getting an interior pointer to items in the
>> stack in Modula-3 -- at least not one that you can upward expose
>> (to callers) via return from a procedure. The difficulty in
>> doing this is that the GC moves objects around and would need to
>> know where your manufactured interior pointer is being held and
>> to which *object* (ie, the open array in this case) it refers so
>> that it can 'fix' the pointer when the array object moves.
>> Modula-3 provides a small concession to obtaining downward
>> exposed interior pointers using the VAR parameter mode. For
>> example you can pass 's[i]' as an actual parameter to a VAR mode
>> formal, effectively passing a pointer to the callee. GC can cope
>> with this in one of two possible ways: 1) "Pin" the array so that
>> it cannot be moved while the interior pointer is held on the
>> stack or registers of any thread (this is the approach that CM3's
>> conservative collector uses for now); or 2) track the creation of
>> such interior pointers and how they are derived from base object
>> references for use during GC. 2) requires much more co-operation
>> from the compiler than the current gcc-based backend (with all of
>> its lovely optimizations and register allocation) is capable of
>> doing. 1) is very cheap and does not impede optimizations and
>> register allocation.
>
> Presumably, this all also applies WITH-bound identifiers, when they
> are
> designators of interior components of heap objects? Are there any
> other
> cases?
>
> --
> -------------------------------------------------------------
> Rodney M. Bates, retired assistant professor
> Dept. of Computer Science, Wichita State University
> Wichita, KS 67260-0083
> 316-978-3922
> rodney.bates at wichita.edu
More information about the M3devel
mailing list