Are D classes proper reference types?
Ola Fosheim Grøstad
ola.fosheim.grostad at gmail.com
Sun Jun 27 07:48:22 UTC 2021
On Friday, 25 June 2021 at 21:05:36 UTC, IGotD- wrote:
> Yes, that's a tradeoff but one I'm willing to take. I'm
> thinking even bigger managed pointers of perhaps 32 bytes which
> has more metadata like the allocated size. Managed languages in
> general have fat pointers which we see everywhere and it is not
> a big deal.
Which languages use fat pointers? C++ may use it (but is not
required to).
> If you are littering pointers you perhaps should refactor your
> code, use an array if loads of objects of the same type.
This is what I want to avoid as it makes refcounting more
difficult. If D classes are reference types then they should
always be referred to through a pointer. If you want to put it in
an array, use a struct.
> Another thing which I'm not that satisfied with D is that there
> is no built in method of expanding member classes into the host
> class like C++ which creates pointer littering and memory
> fragmentation.
Not sure what you mean by expanding? I never liked `alias this`
for structs, inheritance would be simpler. Is this what you mean
by expanding?
I think classes in C++ are usually used more like structs in D.
C++ programmers tend to avoid using virtuals, so D-style classes
(C++ classes with virtual members) tend to be a smaller part of
C++ codebases (but it depends on the project, obviously).
More information about the Digitalmars-d-learn
mailing list