Static array size limit

Jonathan M Davis jmdavisProg at gmx.com
Sat Apr 2 06:43:09 PDT 2011


On 2011-04-02 06:21, simendsjo wrote:
> http://digitalmars.com/d/2.0/arrays.html says static arrays are
> limited to 16mb, but I can only allocate 1mb.
> My fault, or bug?
> 
> 	enum size = (16 * 1024 * 1024) / int.sizeof;
> 	//int[size] a;   // Error: index 4194304 overflow for static
> array
> 	enum size2 = (16 * 1000 * 1000) / int.sizeof;
> 	//int[size2] b; // Stack Overflow
> 	//int[250_001] c; // Stack Overflow
> 	int[250_000] d; // ok

Well, 16 * 1024 * 1024 certainly isn't going to work when it's an array ints. 
An int is 4 bytes. So, the max would be more like 4 * 1024 * 1024, and that's 
assuming no overhead (which there may or may not be). Now, 4 * 1024 * 1024 is 
4_194_304, which is definitely more than 250_000, so if 16mb is indeed the 
limit, I don't know why you can't create one greater than 250_000, but you're 
_not_ going to be able to create one of length 16 * 1024 * 10243. That would 
be 64mb.

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list