-
September 24th, 2014, 03:00 AM
#1
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
-
September 24th, 2014, 04:20 AM
#2
Re: What is the usual maximum size of stack of a win32 program?
Victor Nijegorodov
-
September 24th, 2014, 08:43 AM
#3
Re: What is the usual maximum size of stack of a win32 program?
Originally Posted by lucky6969b
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.
-
September 26th, 2014, 04:28 AM
#4
Re: What is the usual maximum size of stack of a win32 program?
Originally Posted by lucky6969b
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.
-
September 26th, 2014, 12:01 PM
#5
Re: What is the usual maximum size of stack of a win32 program?
Originally Posted by razzle
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|