Home All Groups Group Topic Archive Search About

Thread constructor - maxStackSize argument?

Author
28 Mar 2006 5:07 PM
TMcM
Framework 2.0

There is a constructor for the System.Threading.Thread class that takes a
ThreadStart object and an int as construction arguments. The ThreadStart
object is the delegate to the thread entry point obviously, but what is the
maxStackSize integer value used for? I can see that it will set the size of
the stack, but in what unit of measure?

Can anyone give me an example of when/why you would want to set the
maxStackSize?

Thanks in advance!

Author
28 Mar 2006 7:48 PM
Mattias Sjögren
>I can see that it will set the size of
>the stack, but in what unit of measure?

I believe it's in bytes.


>Can anyone give me an example of when/why you would want to set the
>maxStackSize?

If you know that you have a deep recursion that would overflow the
default stack size, or if you need to store lots of data on the stack.
It's not exactly a common thing to do.


Mattias

--
Mattias Sjögren [C# MVP]  mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Author
28 Mar 2006 8:27 PM
TMcM
That makes sense.

Thanks a bunch Mattias!

Show quote
"Mattias Sjögren" wrote:

>
> >I can see that it will set the size of
> >the stack, but in what unit of measure?
>
> I believe it's in bytes.
>
>
> >Can anyone give me an example of when/why you would want to set the
> >maxStackSize?
>
> If you know that you have a deep recursion that would overflow the
> default stack size, or if you need to store lots of data on the stack.
> It's not exactly a common thing to do.
>
>
> Mattias
>
> --
> Mattias Sjögren [C# MVP]  mattias @ mvps.org
> http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
> Please reply only to the newsgroup.
>
Author
29 Mar 2006 6:34 AM
Nick Hounsome
Show quote
"TMcM" <T***@discussions.microsoft.com> wrote in message
news:876C7B31-A35D-473A-97D2-44FDFC47E341@microsoft.com...
> Framework 2.0
>
> There is a constructor for the System.Threading.Thread class that takes a
> ThreadStart object and an int as construction arguments. The ThreadStart
> object is the delegate to the thread entry point obviously, but what is
> the
> maxStackSize integer value used for? I can see that it will set the size
> of
> the stack, but in what unit of measure?
>
> Can anyone give me an example of when/why you would want to set the
> maxStackSize?

The documentation says to avoid using it.

This is sounds like good advice since you have no idea how much stack a call
to a framework method will take and it's a no brainer that such calls are
likely to be the deepest since any method you write will call framework
methods. MS could at least have done the tests to come up with a good
number.

It would probably be morse sensible to specify a minimum stack size for when
you know that you are going to do some deep recursion.

AddThis Social Bookmark Button