Is it possible to avoid call to destructor for structs?

bitwise bitwise.pvt at gmail.com
Mon Sep 25 14:59:12 UTC 2017


On Monday, 25 September 2017 at 08:39:26 UTC, Adrian Matoga wrote:
> [...]
>
> You shouldn't store the pointer to barBuffer inside Foo. The 
> language allows moving the structure around with a simple 
> memcpy, so _bar is likely to point into garbage soon after it's 
> assigned.

Good point - but it's a mistake ;) 'Foo' is a class in the OP's 
code, so no problem.

> Why don't you just return *cast(Bar*)barBuffer.ptr in bar()?

Lazy construction

> You could still emplace a Bar inside barBuffer in Foo's 
> constructor, if needed.

So you KNOW it's a class then...since structs can't have default 
ctors.. :P



More information about the Digitalmars-d-learn mailing list