Hi Fred,
I think that because C# on top of CLR is completely 'managed' - ie. memory
and stack allocations are handled under the cover.
C#/managed are compiled to IL - code is run in a virtual machine
environment.
There is also a set of API to allow finer control over memory allocation
for hosts in the coming version of .Net Framework.
Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! -
www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
--------------------
| From: "Fred Mellender" <
[email protected]>
| Newsgroups: microsoft.public.dotnet.languages.csharp
| References: <#
[email protected]>
<#
[email protected]>
<
[email protected]> <
[email protected]>
<
[email protected]>
| Subject: Re: Stack Size
| Lines: 145
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Message-ID: <
[email protected]>
| X-Complaints-To: (e-mail address removed)
| X-Trace:
52616e646f6d495603120f292ac5ee1f96e15ff40a2890a76ee2e67f3baecd4d8941f5b87c8e
5d6e5833b660d4c3166e956bfc51cc3f300260143400fe3142f055e9ae0f831dd0e6503ac8d4
e25f2ae19e5806bb4028cd1de6103810f79e0835853ba16c478c11dc9c644967267b9d7d
| X-Abuse-Info: Please be sure to forward ALL headers so that we may
process your complaint properly.
| NNTP-Posting-Date: Mon, 13 Oct 2003 09:48:28 GMT
| Date: Mon, 13 Oct 2003 09:48:28 GMT
| Path:
cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!news-out.cwix.com!news-out!news!ne
wsfeed.cwix.com!prodigy.com!in.100proofnews.com!in.100proofnews.com!news-xfe
r.cox.net!peer01.cox.net!peer02.cox.net!cox.net!news-feed01.roc.ny.frontiern
et.net!nntp.frontiernet.net!news02.roc.ny.POSTED!not-for-mail
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.csharp:190916
| X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
|
| Thanks for the information and it is good to know there is a work-around.
|
| However, I see that the solution requires writing in C++ and use of the
| "_asm" keyword. Perhaps there is no way for C# to accomplish the same
thing
| in a "managed" way? I'm sure the C# designers have plenty on their plates
| already, but it would be nice to see the stack growth handled
automatically,
| or perhaps through a more "C# pure" exception handler.
|
| But the information you provided is useful to me. I am working on a
| Prolog-like system where recursion is often a substitute for loops.
|
|
| | >
| > Hi Fred,
| >
| > The stack is set to an arbitrarily small value when the program is first
| > loaded. The stack then grows on demand to meet the needs of the thread.
| > This is implemented by placing a page with PAGE_GUARD access at the end
of
| > the current stack. When your code causes the stack pointer to point to
an
| > address on this page, an exception occurs. The system will commit your
| > desired page. The 1M was the default maximum stack size that can be
| commit.
| >
| > To work around the recursive problem, you can handle the over flow
| > exception, commit more page yourself, for more details please refer to
| > "Trapping the Exception with __try and __except (Full Solution)" in the
| > link below:
| >
http://support.microsoft.com/default.aspx?scid=kb;en-us;315937
| >
| > Hope this helps,
| > Best regards,
| > Jeffrey Tan
| > Microsoft Online Partner Support
| > Get Secure! -
www.microsoft.com/security
| > This posting is provided "as is" with no warranties and confers no
rights.
| >
| > --------------------
| > | From: "Fred Mellender" <
[email protected]>
| > | Newsgroups: microsoft.public.dotnet.languages.csharp
| > | References: <#
[email protected]>
| > <#
[email protected]>
| > <
[email protected]>
| > | Subject: Re: Stack Size
| > | Lines: 60
| > | X-Priority: 3
| > | X-MSMail-Priority: Normal
| > | X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| > | Message-ID: <
[email protected]>
| > | X-Complaints-To: (e-mail address removed)
| > | X-Trace:
| >
|
52616e646f6d4956a7c2f1d1725bf9c71a51cc963cf8af61d4bf1cb8db7ce0b5f504894fa320
| >
|
62d943d8f53fcbaf8e94930c7856e7b450326e8242345776f33dd68c3bef19dbe75a3af0e5b3
| > 07cff1b21e7500f5b9f8df775dc4ecaf6611d9ba8fc8cb03247f51d5bca10438b45eabb4
| > | X-Abuse-Info: Please be sure to forward ALL headers so that we may
| > process your complaint properly.
| > | NNTP-Posting-Date: Sat, 11 Oct 2003 12:07:41 GMT
| > | Date: Sat, 11 Oct 2003 12:07:41 GMT
| > | Path:
| >
|
cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!news-out.cwix.com!newsfeed.cwix.co
| >
|
m!prodigy.com!rip!news.webusenet.com!peer01.cox.net!cox.net!newshosting.com!
| >
|
news-xfer2.atl.newshosting.com!news-feed01.roc.ny.frontiernet.net!nntp.front
| > iernet.net!news01.roc.ny.POSTED!not-for-mail
| > | Xref: cpmsftngxa06.phx.gbl
| microsoft.public.dotnet.languages.csharp:190709
| > | X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
| > |
| > | If the answer is not too arcane can someone explain to me why the
stack
| > size
| > | had to be set at compile/load time. Why did the c# designers not
grow
| it
| > | as required in virtual memory, which (so far as I know) is done by
most
| > | other language implementations, and let an "out of memory" exception
| > occur?
| > |
| > | In an object oriented language where most objects are allocated on the
| > heap,
| > | perhaps it is not so important. Nevertheless, some problems are most
| > easily
| > | coded as a recursive function and, if even a few value types are
used, a
| > 1MB
| > | stack does not seem like much.
| > |
| > | E.G. (not too realistic, maybe, given that a double would not hold the
| > | answer anyway):
| > | public static double fact(double x)
| > |
| > | {
| > |
| > | if (x <= 0)
| > |
| > | return 1;
| > |
| > | return x *fact(x-1);
| > |
| > | }
| > |
| > | overflows when fact(35000) is called. ("An unhandled exception of
type
| > | 'System.StackOverflowException' occurred in Foo.exe"). So less than
| 35000
| > | recursive calls can occur in a function that uses type double as a
| > | parameter?
| > |
| > | | > | > Thanks Mattias,
| > | >
| > | > I had hoped there was a compiler option, but at least there is a
way.
| > | >
| > | > Ben
| > | >
| > | >
| > | > | > | > > Ben,
| > | > >
| > | > > >Is it possible to change the StackSize in .NET? If so how?
| > | > >
| > | > > Editbin.exe /stack
| > | > >
| > | > > should work, I think.
| > | > >
| > | > >
| > | > >
| > | > > Mattias
| > | > >
| > | > > --
| > | > > Mattias Sjögren [MVP] mattias @ mvps.org
| > | > >
http://www.msjogren.net/dotnet/
| > | > > Please reply only to the newsgroup.
| > | >
| > | >
| > |
| > |
| > |
| >
|
|
|