D Language Foundation October 2023 Quarterly Meeting Summary

Nick Treleaven nick at geany.org
Sun Dec 10 18:16:05 UTC 2023


On Wednesday, 6 December 2023 at 16:28:08 UTC, Mike Parker wrote:
> One way to do that in D is to use `alloca`, but that's an issue 
> because the memory it allocates has to be used in the same 
> function that calls the `alloca`. So you can't, e.g., use 
> `alloca` to alloc memory in a constructor, and that prevents 
> using it in a custom array implementation.

You can call `alloca` as a default argument to a function. The 
memory will be allocated on the caller's stack before calling the 
function:
https://github.com/ntrel/stuff/blob/master/util.d#L113C1-L131C2

I've just tested and it seems it works as a constructor default 
argument too.


More information about the Digitalmars-d-announce mailing list