What should happen here?
Steven Schveighoffer
schveiguy at gmail.com
Fri Sep 24 12:10:41 UTC 2021
On 9/23/21 5:34 PM, IGotD- wrote:
> On Thursday, 23 September 2021 at 19:54:56 UTC, Steven Schveighoffer wrote:
>>
>> 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...
>>
>
> It doesn't matter where it is, stack or register. What is important is
> that the pointer value is retained somewhere. KeepAlive should trick the
> compiler to believe that KeepAlive itself is a user of the resource. How
> that is done in practice is another question and may vary depending on
> GC type.
Right, the registers are scanned too. In fact, I'm pretty sure when
looking at the code LDC generates when using my latest keepalive lib, it
can use a non-temporary register to store the pointer, and then when it
comes time to call the destructor, it puts the pointer on the stack
(because destructors require a pointer).
And a register is even more performant than the stack!
-Steve
More information about the Digitalmars-d
mailing list