Thread Stack Size

來源:互聯網
上載者:User
http://msdn.microsoft.com/en-us/library/ms686774(VS.85).aspx

 MSDN

  • MSDN Home
  • MSDN Library
  • MSDN Learn
  • MSDN Downloads
  • MSDN Support
  • MSDN Community

MSDN Library
  • Design Tools
  • Development Tools and Languages
  • Mobile and Embedded Development
  • .NET Development
  • Office Development
  • Open Specifications
  • Servers and Enterprise Development
  • Web Development
  • Win32 and COM Development

Win32 and COM Development
  • Administration and Management
  • Component Development
  • Data Access and Storage
  • Development Guides
  • Diagnostics
  • Graphics and Multimedia
  • Messaging and Collaboration
  • Mobile PC
  • Networking
  • Security
  • System Services
  • Tools
  • User Interface
  • Windows Search
  • Windows Driver Kit
  • Windows Logo Kit
  • Windows Versions
  • XML
  • Technical Articles

System ServicesPlease Wait

DLLs, Processes, and ThreadsPlease Wait

Processes and ThreadsPlease Wait

About Processes and Threads
  • Multitasking
  • Scheduling
  • Multiple Threads
  • Child Processes
  • Thread Pools
  • Job Objects
  • Fibers

Multiple Threads
  • Thread Stack Size
  • Thread Handles and Identifiers
  • Suspending Thread Execution
  • Synchronizing Execution of Multiple Threads
  • Multiple Threads and GDI Objects
  • Thread Local Storage
  • Creating Windows in Threads
  • Terminating a Thread
  • Thread Security and Access Rights

 Thread Stack Size

Thread Stack Size

Each
new thread or fiber receives its own stack space consisting of both
reserved and initially committed memory. The reserved memory size
represents the total stack allocation in virtual memory. As such, the
reserved size is limited to the virtual address range. The initially
committed pages do not utilize physical memory until they are
referenced; however, they do remove pages from the system total commit
limit, which is the size of the page file plus the size of the physical
memory. The system commits additional pages from the reserved stack
memory as they are needed, until either the stack reaches the reserved
size minus one page (which is used as a guard page to prevent stack
overflow) or the system is so low on memory that the operation fails.

It
is best to choose as small a stack size as possible and commit the
stack that is needed for the thread or fiber to run reliably. Every
page that is reserved for the stack cannot be used for any other
purpose.

A stack is freed when its thread exits. It is not freed if the thread is terminated by another thread.

The
default size for the reserved and initially committed stack memory is
specified in the executable file header. Thread or fiber creation fails
if there is not enough memory to reserve or commit the number of bytes
requested. The default stack reservation size used by the linker is 1
MB. To specify a different default stack reservation size for all
threads and fibers, use the STACKSIZE statement in the module
definition (.def) file. The operating system rounds up the specified
size to the nearest multiple of the system's allocation granularity
(typically 64 KB). To retrieve the allocation granularity of the
current system, use the GetSystemInfo function.

To change the initially committed stack space, use the dwStackSize parameter of the
CreateThread,
CreateRemoteThread, or CreateFiber
function. This value is rounded up to the nearest page. Generally, the
reserve size is the default reserve size specified in the executable
header. However, if the initially committed size specified by dwStackSize
is larger than or equal to the default reserve size, the reserve size
is this new commit size rounded up to the nearest multiple of 1 MB.

To change the reserved stack size, set the dwCreationFlags parameter of
CreateThread or
CreateRemoteThread to STACK_SIZE_PARAM_IS_A_RESERVATION and use the dwStackSize
parameter. In this case, the initially committed size is the default
size specified in the executable header. For fibers, use the dwStackReserveSize parameter of
CreateFiberEx. The committed size is specified in the dwStackCommitSize parameter.

The SetThreadStackGuarantee
function sets the minimum size of the stack associated with the calling
thread or fiber that will be available during any stack overflow
exceptions.

Send comments about this topic to Microsoft

Build date: 8/7/2008

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.