On 7/20/20 8:16 PM, a...@a.com wrote:

>> 3) Lastly, In the following code snippet, is arrayA and arrayB both
>> allocated on the stack?

arrayA is allocated on thread-local storage and lives as long as the program is active. I guess a final interaction with it can be in a 'static ~this()' or a 'shared static ~this()' block.

Note that this is different from e.g. C++: In that language, arrayA would be a "global" variable and there would be a single instance of it. In D, there will be as many arrayA variables as there are active threads. (One thread's modification to its own arrayA is not seen by other threads.)

arrayB is allocated on the stack and lives as long as the scope that it is defined inside. That scope is main's body in your code.

> And how does their scopes and/or lifetimes
>> differ?
>>
>> ==== module1 =====
>> int[100] arrayA;
>> void main()
>> {
>>     int[100] arrayB;
>>     // ...
>> }
>> ==== module1 =====

Ali

Reply via email to