Are D classes proper reference types?

IGotD- nise at nise.com
Sun Jun 27 09:35:10 UTC 2021


On Sunday, 27 June 2021 at 07:48:22 UTC, Ola Fosheim Grøstad 
wrote:
>
>
> Which languages use fat pointers? C++ may use it (but is not 
> required to).

Probably about all managed languages. One common method is a that 
it is actually an identifier it is used in a hash table. Then you 
can find all sorts of meta data in there. My original point was 
that this consume more memory in managed languages but nobody 
seems to mind.

>
> 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?
>

When you use a struct as a member variable in another struct the 
data will be expanded into the host struct. If the member struct 
is 16 bytes then the host struct will have grow 16 bytes to 
accommodate that member struct.

This is not the case in D with classes as classes always are 
allocated on the heap using dynamic allocation. This leads to 
more fragmentation and memory consumption.


More information about the Digitalmars-d-learn mailing list