Array: Difference between revisions

Content added Content deleted
Line 67: Line 67:
</lang>
</lang>


It is <b>much</b> easier to work with arrays in assembly if all rows are the same length. The best way to deal with a ragged or jagged array is to pad the ends of each shorter row with arbitrary bytes. This lets you select an arbitrary row with a simple bit shift applied to the index.
It is <b>much</b> easier to work with arrays in assembly if all rows are the same length. The best way to deal with a ragged or jagged array, such as an array of strings of different lengths, is to store ''pointers to the array entries rather than the intended entries themselves.'' This equalizes the size of all the elements of the array which makes it much easier to index. Another way to handle such arrays is with padding, by adding extra null bytes to the ends until all rows are the same length, but for many data types it's better to construct an array of pointers.