Where can find fix length array memory layout document

lili akozhao at tencent.com
Tue Jun 18 13:05:03 UTC 2019


On Tuesday, 18 June 2019 at 12:39:45 UTC, Dennis wrote:
> On Tuesday, 18 June 2019 at 12:26:14 UTC, lili wrote:
>> Hi guys:
>>    Is the Dlang fix-length array alloc on stack?  when a test
>>     writeln([1]).sizeof //16
>>     writeln([2]).sizeof //16
>>     Why, What is the fix-length array memory layout.
>
> I'm assuming you mean writeln([1].sizeof).
> An array literal is a slice of a dynamic array (which is length 
> + pointer, so 2*size_t size).
> A fixed size array has to be declared as a local / member 
> variable, and then the content is on the stack:
>
> ```
> int[10] a;
> writeln(a.sizeof); // 40
> writeln(a[].sizeof); // 16 on 64-bit or 8 on 32-bit
> ```
>
> To get a static array literal, you can use the library function 
> staticArray:
> ```
> import std.array;
> writeln([1, 2, 3].staticArray.sizeof); // 12
> ```
Thanks a lot, where is a core.stdcpp.array , How to user it?
I test  but get a error
```
   auto aa = array!(int, 4); //error
```


More information about the Digitalmars-d-learn mailing list