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.
    • Re: D La... Richard (Rikki) Andrew Cattermole via Digitalmars-d-announce
      • Re: ... Bastiaan Veelo via Digitalmars-d-announce
        • ... Nicholas Wilson via Digitalmars-d-announce
          • ... Bastiaan Veelo via Digitalmars-d-announce
            • ... Nicholas Wilson via Digitalmars-d-announce
              • ... Sergey via Digitalmars-d-announce
            • ... Nicholas Wilson via Digitalmars-d-announce
    • Re: D La... Siarhei Siamashka via Digitalmars-d-announce
      • Re: ... Bastiaan Veelo via Digitalmars-d-announce
    • Re: D La... Guillaume Piolat via Digitalmars-d-announce
  • Re: D Languag... Nick Treleaven via Digitalmars-d-announce
    • Re: D La... Bastiaan Veelo via Digitalmars-d-announce
  • Re: D Languag... Timon Gehr via Digitalmars-d-announce
  • Re: D Languag... monkyyy via Digitalmars-d-announce

Reply via email to