My Long Term Vision for the D programming language
max haughton
maxhaton at gmail.com
Thu Nov 25 15:37:31 UTC 2021
On Thursday, 25 November 2021 at 09:29:49 UTC, Elronnd wrote:
> On Thursday, 25 November 2021 at 02:32:41 UTC, max haughton
> wrote:
>> the key thing with this scope transformation isn't stack
>> allocation but rather moving the allocation anywhere other
>> than the GC.
>
> I am not quite sure what you are saying. Are you saying that:
>
> 1. The problem is moving the allocation somewhere other than
> the gc, including potentially to the stack, or to an alternate
> heap, or to somewhere else; or,
>
> 2. Converting allocations from gc to the stack is fine; but
> moving them anywhere else is problematic
>
> In either case, this compiles currently and produces GC-free
> code:
>
> @nogc:
> void f(scope int[] x);
> void g(int x, int y) { f([x, y]); }
>
> I'm not sure where you would want to move scope allocations to
> aside from the stack, as scope guarantees LIFO, and so is the
> perfect fit for a stack. Perhaps an alternate stack (cf 'brk')
> managed in druntime, to avoid stack overflow? That would be
> good, but is hardly a challenging transformation if you can
> already produce regular stack allocation.
Just use malloc and free. If you want to be clever stick a branch
in there or forward to a tuned allocator. The fact that the stack
is LIFO makes absolutely no difference compared to the cost of
calling into the GC and even worse potentially causing a
collection.
More information about the Digitalmars-d
mailing list