miscellaneous array questions...

Steven Schveighoffer schveiguy at gmail.com
Tue Jul 21 12:28:20 UTC 2020


On 7/21/20 7:10 AM, IGotD- wrote:
> 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.

I believe it stems from a limitation in the way the stacks are 
allocated? Or maybe a limitation in DMC, the basis for DMD.

Also, you CAN actually have larger arrays, they just cannot be put on 
the stack (which most static arrays are):

struct S
{
     ubyte[17_000_000] big;
}

void main()
{
     auto s = new S; // ok
     S s; // crash (signal 11 on run.dlang.io)
}

This may not work if `big` had a static initializer, I'm not sure.

-Steve


More information about the Digitalmars-d-learn mailing list