[Coco] Array Storage in DECB

Robert Gault robert.gault at worldnet.att.net
Thu Jan 29 17:52:56 EST 2009


Darren A wrote:
> On 1/29/09, CoCo Mongrel wrote:
>> Hi CoCo folks!
>>
>> < snip >
>>
>> I've got a couple of one-dimentioned arrays, now called human_handval(5) and
>> cmp_handval(5).  I could make more generalized subroutines if I could pack
>> those arrays into a single multidimensional array and do something like
>> this:
>>
>> handval(curplyr,i)
>>
>> My question is what that does for memory use.  I'm fairly sure I can
>> eliminate quite a bit of redundant program code by not needing separate
>> subroutines for the human player and the computer player.  Intuitively, I
>> would guess that a multidimensional array shouldn't take any more storage
>> space in RAM than two single dimensional arrays, and perhaps slightly less.
>> But I bet somebody on this list has more than an intuitive guess on this
>> matter.
> 
>>From "Color Basic Unravelled":
> 
> Each element in an array requires 5 bytes of storage and the format of
> the 5-byte block is the same as simple variables. Arrays are stored in
> the array table and each array is preceded by a header block of 5+2*N
> bytes where N = number of dimensions in the array. The first two bytes
> contain the name of the array, the next two bytes contain the total
> length of array items and header block, the fifth byte contains the
> number of dimensions and, finally, 2 bytes per each dimension contain
> the length of the dimension.
> 
> So, converting two single dimensioned arrays into one
> multi-dimensioned array will actually reduce storage size by 5 bytes!
> 
> Darren
> 

Which indicates that ROM Basic arrays use more bytes than the actual 
data if the data consists of numbers 0-255; ie. the values are Reals. 
Put another way, if you do the work with an access routine, you can use 
any size block of memory divided into rows and columns where each byte 
is a data point.
The arrays get much larger if they are string arrays.



More information about the Coco mailing list