4 ms·
So, are there high-level languages that make it easy to write classes that include length-varies-by-instance member(s) in their memory layout? That could be a
by Someone 10y ago
So, are there high-level languages that make it easy to write classes that include length-varies-by-instance member(s) in their memory layout?
That could be a huge efficiency gain because of cache misses.
- twic 10y agoSmalltalk has that: https://www.gnu.org/software/smalltalk/manual-base/html_node/Class_002dinstance-creation.html https://www.gnu.org/software/smalltalk/manual-base/html_node... https://www.gnu.org/software/smalltalk/manual/html_node/Inside-Arrays.html https://www.gnu.org/software/smalltalk/manual/html_node/Insi... Although see the footnote - "This is not always true for other Smalltalk implementations, who don't allow instance variables in variableByteSubclasses and variableWordSubclasses". So, in some implementations, you can have either normal fields or array slots, but not both. That said, i think if you have a base class with fields, you can always make a subclass with slots.
- pjmlp 10y agoI imagine Eiffel, Modula-3 and Ada are possible candidates, but would need to research it.
- masklinn 10y agoRust has unsized (aka dynamically-sized) types, trait objects and slices are probably the most commonly encountered DSTs. There are two main limitations to them: * by default most generic code can not operate over them, generics require the special `?Sized` bound to allow DSTs (essentially generics have a default Sized generic bound) * Rust doesn't currently support dynamic stack allocation so DSTs can't be stack-allocated (https://github.com/rust-lang/rfcs/issues/618 https://github.com/rust-lang/rfcs/issues/618)
- matthewwarren 10y agoThanks for asking this, I didn't even think about other languages and if they made this possible or not
- needusername 10y agoThere is a proposal for Java http://objectlayout.org/ http://objectlayout.org/