digitalmars.D.learn - Static array size limit
- simendsjo (10/10) Apr 02 2011 http://digitalmars.com/d/2.0/arrays.html says static arrays are
- simendsjo (1/1) Apr 02 2011 This is using dmd 2.052 on windows by the way.
- Jonathan M Davis (9/20) Apr 02 2011 Well, 16 * 1024 * 1024 certainly isn't going to work when it's an array ...
- simendsjo (6/6) Apr 02 2011 I think you missed my "/int.sizeof" at the end.
- bearophile (4/7) Apr 02 2011 It accepts 4_000_000 ints, but not (16 * 1024 * 1024) / int.sizeof = 4_1...
- simendsjo (2/9) Apr 02 2011 The main problem is that it gives a Stack Overflow already at 250_001
- bearophile (5/6) Apr 02 2011 I meant with the array as a global variable.
- Steven Schveighoffer (5/12) Apr 04 2011 That would be 16 MiB.
- bearophile (4/7) Apr 04 2011 Then I think 16 MiB are more useful than 16_000_000 bytes.
- Steven Schveighoffer (5/10) Apr 04 2011 Seems arbitrary to me. I'm sure some people feel 32MB would be more
- Jonathan M Davis (5/20) Apr 04 2011 Most of the time that anyone talks about megabytes, they mean mebibytes,...
- simendsjo (4/4) Apr 04 2011 And it seems also Walter is meaning mebibytes:
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
Apr 02 2011
This is using dmd 2.052 on windows by the way.
Apr 02 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; // okWell, 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
Apr 02 2011
I think you missed my "/int.sizeof" at the end. enum size = (16*1024*1024)/int.sizeof; int[size] a; // "Error index overflow for static" as expected int[size-1] b; // stack overflow int[250_001] c; // stack overflow int[250_000] d; // ok
Apr 02 2011
simendsjo: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?It accepts 4_000_000 ints, but not (16 * 1024 * 1024) / int.sizeof = 4_194_304 ints. I don't know why it's designed this way... I'd like 4_194_304 ints. Bye, bearophile
Apr 02 2011
On 02.04.2011 16:45, bearophile wrote:simendsjo:The main problem is that it gives a Stack Overflow already at 250_001http://digitalmars.com/d/2.0/arrays.html says static arrays are limited to 16mb, but I can only allocate 1mb. My fault, or bug?It accepts 4_000_000 ints, but not (16 * 1024 * 1024) / int.sizeof = 4_194_304 ints. I don't know why it's designed this way... I'd like 4_194_304 ints. Bye, bearophile
Apr 02 2011
simendsjo:The main problem is that it gives a Stack Overflow already at 250_001I meant with the array as a global variable. The stack on Windows can be set very large too, with -L/STACK:10000000 Bye, bearophile
Apr 02 2011
On Sat, 02 Apr 2011 10:45:51 -0400, bearophile <bearophileHUGS lycos.com> wrote:simendsjo:That would be 16 MiB. http://en.wikipedia.org/wiki/Mebibyte -Stevehttp://digitalmars.com/d/2.0/arrays.html says static arrays are limited to 16mb, but I can only allocate 1mb. My fault, or bug?It accepts 4_000_000 ints, but not (16 * 1024 * 1024) / int.sizeof = 4_194_304 ints. I don't know why it's designed this way... I'd like 4_194_304 ints.
Apr 04 2011
Steven Schveighoffer:That would be 16 MiB. http://en.wikipedia.org/wiki/MebibyteThen I think 16 MiB are more useful than 16_000_000 bytes. Bye, bearophile
Apr 04 2011
On Mon, 04 Apr 2011 12:43:03 -0400, bearophile <bearophileHUGS lycos.com> wrote:Steven Schveighoffer:Seems arbitrary to me. I'm sure some people feel 32MB would be more useful. -SteveThat would be 16 MiB. http://en.wikipedia.org/wiki/MebibyteThen I think 16 MiB are more useful than 16_000_000 bytes.
Apr 04 2011
On 2011-04-04 06:37, Steven Schveighoffer wrote:On Sat, 02 Apr 2011 10:45:51 -0400, bearophile <bearophileHUGS lycos.com> wrote:Most of the time that anyone talks about megabytes, they mean mebibytes, so I think that it's unrealistic to expect that anyone is going to see 16MB and think that it means 16_000_000 bytes reather than 16_777_216 bytes. - Jonathan M Davissimendsjo:That would be 16 MiB. http://en.wikipedia.org/wiki/Mebibytehttp://digitalmars.com/d/2.0/arrays.html says static arrays are limited to 16mb, but I can only allocate 1mb. My fault, or bug?It accepts 4_000_000 ints, but not (16 * 1024 * 1024) / int.sizeof = 4_194_304 ints. I don't know why it's designed this way... I'd like 4_194_304 ints.
Apr 04 2011
And it seems also Walter is meaning mebibytes: enum size = (16*1024*1024)/int.sizeof; static assert(!__traits(compiles, int[size])); static assert(__traits(compiles, int[size-1]));
Apr 04 2011