[M3devel] small array in modula-3?

Rodney M. Bates rodney.bates at wichita.edu
Fri Nov 16 22:54:56 CET 2007



Darko wrote:
> Is it really four words? I would have thought it might need a type  
> reference and a size, what are the others for?
> 
One word for the pointer in the stack variable or wherever the real
data would be, if not heap allocated.

One word at negative offset in the heap object for the allocator/collector
to keep track of memory.  This is as low as heap manager space overhead gets,
as far as I know.  In any case, unless somebody figured out how to get it
down to zero, there would still just about have to be a full word because
of alignment.

One word of "shape" for each open dimension, when the object is an open array.
This example is one-dimensional, so it's one word total.

One word (actually appears before the shape (which varies in size), so its
location is consistent for all open array heap objects).  This is a pointer
to the zero-th actual array element.  For a heap allocated open array, this
is redundant, as it always points to the word following the shape.  I presume
the implementors did this because open array formal parameters need a consistent
representation, regardless of whether the formal is an open array, a fixed array,
or a SUBARRAY.  It should be possible to implement less extravagantly, but it
would complicate the compiler with more combinations of cases to handle.
> 
> On 15/11/2007, at 4:39 PM, Rodney M. Bates wrote:
> 
>> Jay wrote:
>>
>> > What is the right way to have a variably sized but always small  
>> array in Modula-3?
>> > My array will only ever have 1 or 2 elements.
>> > I'd like to always allocate room for 2 elements, and have there  be 
>> a size.
>> >
>> > It seems I have a choice of
>> >
>> > a) an "open" array
>>
>> Heap allocated, I presume?  If the max size is only 2 elements,
>> this is pretty extravagant, as a heap allocated open array will
>> have 4 extra behind-the-scenes words of space overhead, plus
>> maybe heap fragmentation, and time overhead of allocation,
>> collection, and maybe reduced locality of reference.
>>

-- 
-------------------------------------------------------------
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