How can I allocate a int[] array on stack?

Jack jckj33 at gmail.com
Fri Mar 26 14:27:58 UTC 2021


On Friday, 26 March 2021 at 06:45:39 UTC, Daniel Kozak wrote:
> On Fri, Mar 26, 2021 at 7:36 AM Daniel Kozak 
> <kozzi11 at gmail.com> wrote:
>
>> On Fri, Mar 26, 2021 at 7:31 AM Daniel Kozak 
>> <kozzi11 at gmail.com> wrote:
>>
>>> On Fri, Mar 26, 2021 at 6:50 AM Jack via Digitalmars-d-learn 
>>> < digitalmars-d-learn at puremagic.com> wrote:
>>>
>>>> What's the equivalent of C's VLA in D? scoped from 
>>>> std.typecons doesn't seem to work with arrays. Should I use 
>>>> alloca() for my array or is there something else?
>>>>
>>>
>>> https://dlang.org/library/std/array/static_array.html
>>>
>> Sorry I was misread this
>>
>
> You can use allocator:
>
> import std.experimental.allocator.showcase;
> import std.experimental.allocator;
> import std.stdio;
>
> StackFront!4096 stackAlloc;
>
> void main() {
>     int[] a = stackAlloc.makeArray!int(2);
>     writeln(a);
> }

I thought this was going to use alloca() but it seems to be using 
malloc() internally?


More information about the Digitalmars-d-learn mailing list