If structures places data to stack why we do not getting stackoverflow on array of structures?

Patrick Schluter via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Aug 16 01:25:17 PDT 2017


On Wednesday, 16 August 2017 at 07:39:01 UTC, Suliman wrote:
>> On the heap, unless you are allocating it via e.g. alloca.
>
> If
> struct MyStruct
> {
>  int x;
>  int y;
> }
>
> MyStruct mystruct;
>
> is located on stack, why:
>
> MyStruct [] mystructs;
>
> should located on heap?

because in D

MyStruct [] mystructs;

is the equivalent of

struct {
    MyStruct *ptr;
    size_t size;
}




More information about the Digitalmars-d-learn mailing list