If structures places data to stack why we do not getting stackoverflow on array of structures?
Steven Schveighoffer via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Wed Aug 16 08:02:09 PDT 2017
On 8/16/17 10:32 AM, Suliman wrote:
> On Wednesday, 16 August 2017 at 13:41:29 UTC, Biotronic wrote:
>> On Wednesday, 16 August 2017 at 12:50:07 UTC, Suliman wrote:
>>>> MyStruct[] is actually a struct similar to this:
>>>>
>>>> struct MyStruct[] {
>>>> MyStruct* ptr;
>>>> size_t length;
>>>> }
>>>>
>>>> That struct is placed on the stack, but the data it points to, via
>>>> the ptr field, is heap allocated.
>>>
>>> What is struct? Just name and size?
>>
>> I'm sorry, I don't understand what you're asking. Can you please
>> repeat with more information?
>>
>> --
>> Biotronic
>
> I am trying to understand what structure is. It's name + associated with
> this name data? I can't understand for my self what mean no put
> structure to stack. Just put it's name to it or something another?
The structure is just a pointer and length. What it points at is not on
the stack, it's in the heap.
This is how a dynamic array works. Indeed:
auto x = new int[10000];
pragma(msg, x.sizeof); // 16LU
-Steve
More information about the Digitalmars-d-learn
mailing list