[ACCEPTED]-Stack capacity in C#-stack

Accepted answer
Score: 74

The default stack size for a .NET application 11 is 1 MB (default is 256 KB for 32-bit ASP.NET 10 apps and 512 KB for 64-bit ASP.NET apps), but 9 you can change that. For the application 8 you can change the default size by modifying 7 the PE header of the executable. For threads 6 you create, you can use the constructor 5 overload that takes a stack size.

But as 4 Anton Tyjhyy points out in his answer, arrays 3 are reference types and thus located on 2 the heap (even if the array happens to hold 1 a bunch of value types).

Score: 55

Your array will live on the heap, stack 1 size is irrelevant in your case.

Score: 7

If you want to check the value for your 9 current .NET assembly then you can do so 8 by using ILDASM command that comes in with Visual 7 Studio command prompt. Once you have started 6 the tool, open your assembly and then go 5 to View -> Headers menu. Now scroll down to PE Optional Header (32 bit) section in 4 the newly opened Headers window. You will see two 3 fields:

  1. Size of stack reserve - This is self-explanatory. This is default stack memory size allocated to any thread getting created in your program/application.
  2. Size of stack commit - committed stack space is - (Quoting Hans Passant from here)

The said space is reserved in the 2 operating system's paging file so the 1 stack can always be swapped out when necessary.

enter image description here

Score: 5

To use stack for storing an array you have 3 to use unsafe code with pointers and stackalloc 2 to allocate desired memory space on the 1 stack.

More Related questions