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