miscellaneous array questions...

IGotD- nise at nise.com
Tue Jul 21 11:10:18 UTC 2020


On Monday, 20 July 2020 at 22:05:35 UTC, WhatMeWorry wrote:
>
> 2) "The total size of a static array cannot exceed 16Mb" What 
> limits this? And with modern systems of 16GB and 32GB, isn't 
> 16Mb excessively small?   (an aside: shouldn't that be 16MB in 
> the reference instead of 16Mb? that is, Doesn't b = bits and B 
> = bytes)
>

I didn't know this but it makes sense and I guess this is a 
constraint of the D language itself. In practice 16MB should be 
well enough for most cases. I'm not sure where 16MB is taken 
from, if there is any OS out there that has this limitation or if 
it was just taken as an adequate limit.

Let's say you have a program with 4 threads, then suddenly the 
TLS area is 4 * 16 MB = 64MB. This size rapidly increases with 
number of threads and TLS area size. Let's say TLS area of 128MB 
and 8 threads, which gives you a memory consumption of 1GB. 
That's how quickly it starts to consume memory if you don't limit 
the TLS variables.

If you want global variables like in good old C/C++, then use 
__gshared. Of course you have to take care if any multiple 
accesses from several threads.



More information about the Digitalmars-d-learn mailing list