CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Dec 2010
    Posts
    907

    What is the usual maximum size of stack of a win32 program?

    I know that if the structure doesn't fit into the stack, it needs to be put onto the heap.
    But what is maximum size of a win32 stack in usual case?
    Thanks
    Jack

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: What is the usual maximum size of stack of a win32 program?

    Victor Nijegorodov

  3. #3
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    4,626

    Re: What is the usual maximum size of stack of a win32 program?

    Quote Originally Posted by lucky6969b View Post
    I know that if the structure doesn't fit into the stack, it needs to be put onto the heap.
    this in't a good guideline.
    Any structure bigger than "a few bytes" does not belong on the stack and should be allocated from the free store. ("heap" is not the right terminology).
    POD's
    Small classes like CString
    a handfull of std::string (note that a std::string is probably A LOT bigger than what you think it is).
    there isn't a hard guideline, and your mileage can vary, but if a single function needs more than 1k stack, you're probably doing things wrong. Even more than 256 is probably already an indication of possible incorrect use.
    note that (for x86/x64) there is a size/performance bonus for keeping the stack usage of a single function below 128 bytes.



    FYI: if you don't change anything. you'll get a 1Mb stack by default.

  4. #4
    Join Date
    Jul 2013
    Posts
    576

    Re: What is the usual maximum size of stack of a win32 program?

    Quote Originally Posted by lucky6969b View Post
    I know that if the structure doesn't fit into the stack, it needs to be put onto the heap. But what is maximum size of a win32 stack in usual case?
    One excellent way to avoid this problem is to use dynamic data structures rather than static. For example use an std::string rather than a C-string and use an std::vector rather than a C-array or std::array.

    Only a small "housekeeping" part of such dynamic structures will be allocated on the stack whereas the bulk of the data, "the content", will be kept on the heap.

  5. #5
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: What is the usual maximum size of stack of a win32 program?

    Quote Originally Posted by razzle View Post
    One excellent way to avoid this problem is to use dynamic data structures rather than static. For example use an std::string rather than a C-string and use an std::vector rather than a C-array or std::array.

    Only a small "housekeeping" part of such dynamic structures will be allocated on the stack whereas the bulk of the data, "the content", will be kept on the heap.
    And another great benefit of this approach is any allocated memory is freed by the dynamic data structures.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured