flatjs
flatjs copied to clipboard
Arrays must carry their length
The current system with raw-memory arrays will not last. Having the length available is highly desirable and will be necessary to support multi-dimensional arrays. Technically it's not hard, just a header before the array (whose size will be rounded up to the array alignment at least, though see below).
Array allocation must then be done with @new, or there must be some way of computing the necessary storage requirement and initializing metadata, as for objects. A first attempt might be @sizeof T.Array(10)
, or T.sizeofArray(10)
, and some T.initArrayInstance(p, 10) => p
.
There is a complication here with the interaction with refs. Suppose we add multidimensional arrays or in-line array fields in structured types, where it is possible to get references to subarrays (row vectors) or the in-line fields. Either those must themselves have headers allocated as part of the arrays, which adds space and complicates layout (because the header size may now have to be divisible by the element size, though there may be workarounds), or there must be a separate header and a level of indirection, which is really not all that desirable. Or we ban refs to row vectors or in-line fields. Maybe something will fall out from the general "ref" discussion, see Issue #20.