miscellaneous array questions...
Ali Çehreli
acehreli at yahoo.com
Tue Jul 21 06:38:19 UTC 2020
On 7/20/20 8:16 PM, a at 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
More information about the Digitalmars-d-learn
mailing list