|
|
|
|
|
by jtolmar
617 days ago
|
|
I agree; the point of a struct type would be to allow a compact memory representation, and you're not going to get it if your constructor can do if(someArg) { a = 1; } else { a = 1; b = 2; }. You don't strictly need known/consistent types, but it sure helps, since otherwise everything needs to be 8 bytes. I don't think a way to read into and out of ArrayBuffers is possible, since these can have pointers in them. I think it needs a StructArray class instead, so there's a way to actually make a compact memory array out of all of this. |
|
Arguably that's worse than what the runtime is able to do today already with hidden classes.
> I don't think a way to read into and out of ArrayBuffers is possible
If you know all the types and only allow structs and primitives, you could use relative pointers to encode the 2nd+ references to structs that appear more than once in the encoded object. You'd need a StructArray for efficient arrays, but a linked list would encode pretty compactly. But you're very right.