[Coco] Array Storage in DECB

Darren A mechacoco at gmail.com
Thu Jan 29 13:22:17 EST 2009


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



More information about the Coco mailing list