GC for noobs
Szymon Gatner
noemail at gmail.com
Thu Feb 27 06:37:13 PST 2014
On Thursday, 27 February 2014 at 14:18:47 UTC, Dicebot wrote:
> On Thursday, 27 February 2014 at 14:14:43 UTC, Namespace wrote:
>> Why not? Overhead? No RAII support?
>
> Simply no reason to use classes, structs have all features I
> need for cases when polymorphism is not necessary (95%+). Being
> value type is also convenient as it leaves more control to the
> programmer and RAII is nice cherry on top.
They actually don't have all the necessary features in D afaiu.
They do have value semantics but can't represent uniqueness
because of missing move d-tor.
For example in C++ I can create a function that returns a Texture
class instance and be sure that it is the only one when receiving
it (because copying is disabled). Then I can always safely
release all resources related to this texture in objects d-tor.
In D I can't use struct for this because I would get double-free
in d-tor so a class instance has to be used instead.
More information about the Digitalmars-d-learn
mailing list