Re: Static array size?

2017-02-09 Thread Arek via Digitalmars-d-learn

On Thursday, 9 February 2017 at 11:22:28 UTC, Suliman wrote:

Docs says that:
"The total size of a static array cannot exceed 16Mb."
But when I am creation array of:
int [1000_000] x; // 1000_000 is equal ~ 0,95MB
app crush on start.

Should it's reserve this memory with guaranty? I mean that 
after app start it should take +0.95MB of RAM in task manager.


First of all, as others said it is 4 bytes * 100, what gives 
about 4MB.
Do you allocate this array on the stack? (local variables are 
created on the stack)
If yes, maybe you've exceeded the size of the stack. Declare the 
array out of the scope of any function and check again.
The size of the stack can be set in the linker 
(http://forum.dlang.org/post/mailman.766.1291253609.21107.digitalmar...@puremagic.com).





Re: Static array size?

2017-02-09 Thread Daniel Kozak via Digitalmars-d-learn

On Thursday, 9 February 2017 at 12:13:36 UTC, Daniel Kozák wrote:

V Thu, 09 Feb 2017 11:22:28 +
Suliman via Digitalmars-d-learn 


napsáno:


Docs says that:
"The total size of a static array cannot exceed 16Mb."
But when I am creation array of:
int [1000_000] x; // 1000_000 is equal ~ 0,95MB
app crush on start.

Should it's reserve this memory with guaranty? I mean that 
after app start it should take +0.95MB of RAM in task manager.


First of all it is 4bytes * 1000_000 = 4000_000 bytes = 4kbyte, 
and it should not crash, are you sure this is the reason why 
app crash?


s/kbyte/megabyte




Re: Static array size?

2017-02-09 Thread jkpl via Digitalmars-d-learn

On Thursday, 9 February 2017 at 12:16:26 UTC, jkpl wrote:

On Thursday, 9 February 2017 at 11:22:28 UTC, Suliman wrote:

Docs says that:
"The total size of a static array cannot exceed 16Mb."
But when I am creation array of:
int [1000_000] x; // 1000_000 is equal ~ 0,95MB
app crush on start.

Should it's reserve this memory with guaranty? I mean that 
after app start it should take +0.95MB of RAM in task manager.


multiply by 4


Also static array is not on the heap so take care to which column 
of the task manager you monitor.


Re: Static array size?

2017-02-09 Thread jkpl via Digitalmars-d-learn

On Thursday, 9 February 2017 at 11:22:28 UTC, Suliman wrote:

Docs says that:
"The total size of a static array cannot exceed 16Mb."
But when I am creation array of:
int [1000_000] x; // 1000_000 is equal ~ 0,95MB
app crush on start.

Should it's reserve this memory with guaranty? I mean that 
after app start it should take +0.95MB of RAM in task manager.


multiply by 4


Re: Static array size?

2017-02-09 Thread Daniel Kozák via Digitalmars-d-learn
V Thu, 09 Feb 2017 11:22:28 +
Suliman via Digitalmars-d-learn 
napsáno:

> Docs says that:
> "The total size of a static array cannot exceed 16Mb."
> But when I am creation array of:
> int [1000_000] x; // 1000_000 is equal ~ 0,95MB
> app crush on start.
> 
> Should it's reserve this memory with guaranty? I mean that after 
> app start it should take +0.95MB of RAM in task manager.

First of all it is 4bytes * 1000_000 = 4000_000 bytes = 4kbyte, and it
should not crash, are you sure this is the reason why app crash?



Re: Static array size limit

2011-04-04 Thread Steven Schveighoffer
On Sat, 02 Apr 2011 10:45:51 -0400, bearophile bearophileh...@lycos.com  
wrote:



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.


That would be 16 MiB.

http://en.wikipedia.org/wiki/Mebibyte

-Steve


Re: Static array size limit

2011-04-04 Thread bearophile
Steven Schveighoffer:

 That would be 16 MiB.
 
 http://en.wikipedia.org/wiki/Mebibyte

Then I think 16 MiB are more useful than 16_000_000 bytes.

Bye,
bearophile


Re: Static array size limit

2011-04-04 Thread Steven Schveighoffer
On Mon, 04 Apr 2011 12:43:03 -0400, bearophile bearophileh...@lycos.com  
wrote:



Steven Schveighoffer:


That would be 16 MiB.

http://en.wikipedia.org/wiki/Mebibyte


Then I think 16 MiB are more useful than 16_000_000 bytes.


Seems arbitrary to me.  I'm sure some people feel 32MB would be more  
useful.


-Steve


Re: Static array size limit

2011-04-02 Thread simendsjo
This is using dmd 2.052 on windows by the way.


Re: Static array size limit

2011-04-02 Thread Jonathan M Davis
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


Re: Static array size limit

2011-04-02 Thread simendsjo
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


Re: Static array size limit

2011-04-02 Thread bearophile
simendsjo:

 The main problem is that it gives a Stack Overflow already at 250_001

I meant with the array as a global variable.
The stack on Windows can be set very large too, with -L/STACK:1000

Bye,
bearophile