Hi Eric, Coming back on memory; I presented two designs:
- in the first one, you have a tag at each level of the hierarchy, which indeed uses more memory for deep hierarchies but means that a type only knows about its immediate children - in the second one, you have a tag only at the root of the hierarchy, which should use exactly as much memory as a v-table pointer (the fact there is no v-table does not matter) Regarding the boilerplate methods, my experience with LLVM is that with virtual the root describes the interface and each descendant implements it whereas in this system the root implements the interface for each and every descendant... This can be alleviated by only dispatching to the immediate descendants (and let them dispatch further) which is more compatible with the memory-heavy design but also means multiple jumps at each call; not nice. However, once the interface is defined, user code should rarely have to go and inspect the hierarchy by itself; this kind of "down-casting" should be limited, as it is with regular inheritance in other languages. -- Matthieu On Thu, Mar 13, 2014 at 7:49 PM, Eric Summers <eric.summ...@me.com> wrote: > Thinking about this a bit more, maybe the memory cost could go away with > tagged pointers. That is easier to do on a 64-bit platform though. > > Eric > > On Mar 13, 2014, at 1:37 PM, Eric Summers <eric.summ...@me.com> wrote: > > > Yes, but with tags you pay the cost even if Option is None. > > > > Eric > > > > On Mar 13, 2014, at 1:33 PM, Daniel Micay <danielmi...@gmail.com> wrote: > > > >> On 13/03/14 02:25 PM, Eric Summers wrote: > >>> Also this approach uses more memory. At least a byte per pointer and > >>> maybe more with padding. In most cases like this you would prefer to > >>> use a vtable instead of tags to reduce the memory footprint. > >>> > >>> Eric > >> > >> A vtable uses memory too. Either it uses a fat pointer or adds at least > >> one pointer to the object. > >> > > > > _______________________________________________ > > Rust-dev mailing list > > Rust-dev@mozilla.org > > https://mail.mozilla.org/listinfo/rust-dev > > _______________________________________________ > Rust-dev mailing list > Rust-dev@mozilla.org > https://mail.mozilla.org/listinfo/rust-dev >
_______________________________________________ Rust-dev mailing list Rust-dev@mozilla.org https://mail.mozilla.org/listinfo/rust-dev