On 9/23/21 3:40 PM, H. S. Teoh wrote:
>On Thu, Sep 23, 2021 at 03:22:26PM -0400, Steven Schveighoffer via Digitalmars-d wrote:
>Hm... it cancels all optimizations. No inlining either, or removal of
the empty function. So the penalty is you are going to call the dtor
(with an actual call instruction).
I guess that's better than nothing.
[...]
All of this long discussion begs the question: why not just use
GC.addRoot() and call it a day?
You can. But wouldn't you prefer just pushing something on the stack?
I don't know, it sort of bugs me and fascinates me that there isn't a way to do this easily. The stack is pretty much free to use, adding something to some allocated tree inside the GC (and then later removing it) isn't.
The use cases are exceedingly small though...
-Steve