Microsoft Knowledge Base Email Alertz

KBAlertz.com: By default, the maximum stack size of a thread that is created in a native IIS process is 256 KB

Receive Microsoft Knowledge Base articles by E-Mail?

Every night we scan the Microsoft Knowledge Base. If technologies you're interested in are updated, we'll send you an e-mail. You only get one e-mail a day, and only when new articles are added.

Click here to create a
FREE account
Already have an account?
[Click here to Login]

Search KbAlertz

Advanced Search

Webmasters
Put kbAlertz on your website.
[ Click Here for more! ]





ASP.NET 3.5 Web Hosting with Windows 2008 and SQL 2008: Click Here!
Discount ASP.NET Hosting
ASP.NET 2.0 and 3.5
Windows2008 and SQL2008
US and UK Hosting
KBAlertz referrals get
** SIX MONTHS FREE **


Community Site



We Send hundreds of thousands of emails using ASP.NET Email


ASP.NET 3.5 Web Hosting with Windows 2008 and SQL 2008: Click Here!
Discount ASP.NET Hosting
ASP.NET 2.0 and 3.5
Windows2008 and SQL2008
US and UK Hosting
KBAlertz referrals get
** SIX MONTHS FREE **




Mentioned In








Microsoft Knowledge Base Article

This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks




Article ID: 932909 - Last Review: April 24, 2007 - Revision: 1.1

By default, the maximum stack size of a thread that is created in a native IIS process is 256 KB

SUMMARY

By default, the maximum stack size of a thread that is created by a native Microsoft Internet Information Services (IIS) process is 256 KB. For example, Inetinfo.exe, DLLHost.exe, or W3wp.exe creates a thread, the maximum stack size of the thread is 256 KB by default. You can also explicitly call the CreateThread function to specify the stack size of the thread. In Microsoft Windows 2000, if the Microsoft ASP.NET Worker Process (ASPNet_wp.exe) creates a thread, the maximum stack size of the thread is 1 MB.

MORE INFORMATION

The maximum stack size of a thread is not determined by an individual ISAPI, DLL, or ASP component that is running inside the process. The maximum stack size of a thread is configured by the executable file of the process. If you must have a large stack size, you can programmatically create a thread and then set the appropriate stack size. Alternatively, if the thread runs out of the maximum stack size, you must change the code in the application to use the stack correctly.

The arguments and the local variables of a function are stored in the stack of the thread. If you declare a local variable that has a very large value, the stack is quickly exhausted. For example, the function in the following code example requires 400,000 bytes in the stack to store the array.
void func(void)
   {
     int i[100000];
     // Use 100,000 integers multiplied by 4 bytes per integer to store the array.
     return;
   }
Note You cannot call this function in IIS 4.0, in IIS 5.0, in IIS 5.1, or in IIS 6.0.

To avoid using the stack, dynamically allocate the memory. For example, the function in the following code example dynamically allocates the memory.
void func(void)
   {
     int *i

     i = new int[100000];
     // More code goes here.
     return;
   }
Note In this code example, the memory is stored in the heap instead of the stack. Therefore, the function does not require 400,000 bytes in the stack to store the array.

If a function is called recursively, the stack may be quickly exhausted. For example, a function requires 400,000 bytes in the stack if the following conditions are true:
  • The function requires 40 bytes for a local variable.
  • The function is recursively called 10,000 times.
In a Common Gateway Interface (CGI) application, a thread does not have a maximum stack size of 256 KB. When you start the CGI application, a new process is created, and the CGI executable files configure the stack size. You can also explicitly call the CreateThread function to specify the stack size of the thread.

For more information, visit the following MSDN Web site:
http://msdn2.microsoft.com/en-us/library/ms686774.aspx (http://msdn2.microsoft.com/en-us/library/ms686774.aspx)

APPLIES TO
  • Microsoft Internet Information Server 4.0
  • Microsoft Internet Information Services 5.0
  • Microsoft Internet Information Services 5.1
  • Microsoft Internet Information Services 6.0
Keywords: 
kbtshoot kbexpertiseadvanced kbinfo KB932909
       

Community Feedback System

Very often, it takes hours to solve a problem. Very often, you've looked high and low, and have tried a lot of solutions. When you finally found it, chances are, it was because someone else helped you. Here's your chance to give back. Use our community feedback tool to let others know what worked for you and what didn't.

Please also understand that the community feedback system is not warranted to be correct, it's simply a system that we've built to let people try and help each other. If something in a feedback response doesn't make sense to you, or you're not comfortable making changes that the feedback talks about (like registry edits), please consult a professional.

Thank you for using kbAlertz.com Feedback System.

-- Scott Cate

Be the first to leave feedback, to help others about this knowledge base article.

(Optional) Name

(Optional) Public URL Or Email

Comments
No HTML -- Text Only Please