473,387 Members | 1,669 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Stack Size

The documentation indicates that the threads "default stack size" is 1MB.
The work "default" implies that it can be changed.

Is it possible to change the StackSize in .NET? If so how?

Is it possible to determine the amount of memory used in the current stack?

Any assistance would be appreciated.

Ben
Nov 15 '05 #1
13 25459
Ben,

Unfortunately no. The documentation you were reading was for the
creation of new threads in the system, which is handled by the Thread class.
The CreateThread API function allows you to set the stack size and you can
call it from .NET. However, I don't know if that is a good idea, since I am
not sure how the runtime will perceive that thread.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- nick(dot)paldino=at=exisconsulting<dot>com

"Ben R. Bolton" <xb*******@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
The documentation indicates that the threads "default stack size" is 1MB.
The work "default" implies that it can be changed.

Is it possible to change the StackSize in .NET? If so how?

Is it possible to determine the amount of memory used in the current stack?
Any assistance would be appreciated.

Ben

Nov 15 '05 #2
Thanks Nicholas,

I hadassumed it couldn't be changed since I could find no reference as to
how to change it. But wanted to ask anyway.

Is it possible to determine how much of the 1MB of memory is currently being
used (is on the stack)?

Ben

"Nicholas Paldino [.NET/C# MVP]" <ni**************@exisconsulting.com> wrote
in message news:eO**************@TK2MSFTNGP09.phx.gbl...
Ben,

Unfortunately no. The documentation you were reading was for the
creation of new threads in the system, which is handled by the Thread class. The CreateThread API function allows you to set the stack size and you can
call it from .NET. However, I don't know if that is a good idea, since I am not sure how the runtime will perceive that thread.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- nick(dot)paldino=at=exisconsulting<dot>com

"Ben R. Bolton" <xb*******@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
The documentation indicates that the threads "default stack size" is 1MB. The work "default" implies that it can be changed.

Is it possible to change the StackSize in .NET? If so how?

Is it possible to determine the amount of memory used in the current

stack?

Any assistance would be appreciated.

Ben


Nov 15 '05 #3

Hi Ben,

It seems that there is no easy way to get the current used stack size of
the thread.
May be you can refer to the NtQueryInformationThread DDK function to get
the information of specified thread.
Because it is a DDK function, you must install the DDK first.

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.

--------------------
| Reply-To: "Ben R. Bolton" <xb*******@hotmail.com>
| From: "Ben R. Bolton" <xb*******@hotmail.com>
| References: <#o**************@TK2MSFTNGP09.phx.gbl>
<eO**************@TK2MSFTNGP09.phx.gbl>
| Subject: Re: Stack Size
| Date: Tue, 7 Oct 2003 12:48:13 -0700
| Lines: 51
| 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: <#f**************@tk2msftngp13.phx.gbl>
| Newsgroups: microsoft.public.dotnet.languages.csharp
| NNTP-Posting-Host: 12-236-76-193.client.attbi.com 12.236.76.193
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftn gp13.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.csharp:189651
| X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
|
| Thanks Nicholas,
|
| I hadassumed it couldn't be changed since I could find no reference as to
| how to change it. But wanted to ask anyway.
|
| Is it possible to determine how much of the 1MB of memory is currently
being
| used (is on the stack)?
|
| Ben
|
|
|
| "Nicholas Paldino [.NET/C# MVP]" <ni**************@exisconsulting.com>
wrote
| in message news:eO**************@TK2MSFTNGP09.phx.gbl...
| > Ben,
| >
| > Unfortunately no. The documentation you were reading was for the
| > creation of new threads in the system, which is handled by the Thread
| class.
| > The CreateThread API function allows you to set the stack size and you
can
| > call it from .NET. However, I don't know if that is a good idea, since
I
| am
| > not sure how the runtime will perceive that thread.
| >
| > Hope this helps.
| >
| >
| > --
| > - Nicholas Paldino [.NET/C# MVP]
| > - nick(dot)paldino=at=exisconsulting<dot>com
| >
| > "Ben R. Bolton" <xb*******@hotmail.com> wrote in message
| > news:%2****************@TK2MSFTNGP09.phx.gbl...
| > > The documentation indicates that the threads "default stack size" is
| 1MB.
| > > The work "default" implies that it can be changed.
| > >
| > > Is it possible to change the StackSize in .NET? If so how?
| > >
| > > Is it possible to determine the amount of memory used in the current
| > stack?
| > >
| > > Any assistance would be appreciated.
| > >
| > > Ben
| > >
| > >
| >
| >
|
|
|

Nov 15 '05 #4
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.
Nov 15 '05 #5
"Mattias Sjögren" <ma********************@mvps.org> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
Ben,
Is it possible to change the StackSize in .NET? If so how?

Editbin.exe /stack
should work, I think.


That works.

Test:

class App {
private static long _Depth = 0;

private static void GoDeep() {
if ((++_Depth % 10000) == 0) System.Console.WriteLine("Depth is " +
_Depth.ToString());
GoDeep();
return;
}

public static void Main() {
try {
GoDeep();
} finally {
}
return;
}
}


editbin /stack:100000,1000 q.exe
Depth is 10000
Depth is 20000

Unhandled Exception: StackOverflowException.

editbin /stack:1000000,1000 q.exe
Depth is 10000
Depth is 20000
Depth is 30000
Depth is 40000
Depth is 50000
Depth is 60000
Depth is 70000
Depth is 80000

Unhandled Exception: StackOverflowException.
-- Alan
Nov 15 '05 #6

Hi Alan,

Yes, that should work, I have found Editbin may be useful for change the
stack size, but I have not had time to test for it.
Thanks for you test code.

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.

--------------------
| Reply-To: "Alan Pretre" <no@spam>
| From: "Alan Pretre" <no@spam>
| References: <#o**************@TK2MSFTNGP09.phx.gbl>
<#p**************@TK2MSFTNGP11.phx.gbl>
| Subject: Re: Stack Size
| Date: Thu, 9 Oct 2003 11:56:23 -0500
| Lines: 55
| 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: <#G**************@TK2MSFTNGP09.phx.gbl>
| Newsgroups: microsoft.public.dotnet.languages.csharp
| NNTP-Posting-Host: host-13-19-220-24.midco.net 24.220.19.13
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP09.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.csharp:190307
| X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
|
| "Mattias Sjögren" <ma********************@mvps.org> wrote in message
| news:%2****************@TK2MSFTNGP11.phx.gbl...
| > Ben,
| > >Is it possible to change the StackSize in .NET? If so how?
| > Editbin.exe /stack
| > should work, I think.
|
| That works.
|
| Test:
|
| class App {
| private static long _Depth = 0;
|
| private static void GoDeep() {
| if ((++_Depth % 10000) == 0) System.Console.WriteLine("Depth is " +
| _Depth.ToString());
| GoDeep();
| return;
| }
|
| public static void Main() {
| try {
| GoDeep();
| } finally {
| }
| return;
| }
| }
|
|
|
|
| editbin /stack:100000,1000 q.exe
| Depth is 10000
| Depth is 20000
|
| Unhandled Exception: StackOverflowException.
|
| editbin /stack:1000000,1000 q.exe
| Depth is 10000
| Depth is 20000
| Depth is 30000
| Depth is 40000
| Depth is 50000
| Depth is 60000
| Depth is 70000
| Depth is 80000
|
| Unhandled Exception: StackOverflowException.
|
|
| -- Alan
|
|
|

Nov 15 '05 #7
Thanks Mattias,

I had hoped there was a compiler option, but at least there is a way.

Ben
"Mattias Sjögren" <ma********************@mvps.org> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
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.

Nov 15 '05 #8
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?

"Ben R. Bolton" <xb*******@hotmail.com> wrote in message
news:OG**************@TK2MSFTNGP09.phx.gbl...
Thanks Mattias,

I had hoped there was a compiler option, but at least there is a way.

Ben
"Mattias Sjögren" <ma********************@mvps.org> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
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.


Nov 15 '05 #9

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...b;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" <no****************@frontiernet.net>
| Newsgroups: microsoft.public.dotnet.languages.csharp
| References: <#o**************@TK2MSFTNGP09.phx.gbl>
<#p**************@TK2MSFTNGP11.phx.gbl>
<OG**************@TK2MSFTNGP09.phx.gbl>
| 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: <ho*****************@news01.roc.ny>
| X-Complaints-To: ab********@frontiernet.net
| X-Trace:
52616e646f6d4956a7c2f1d1725bf9c71a51cc963cf8af61d4 bf1cb8db7ce0b5f504894fa320
62d943d8f53fcbaf8e94930c7856e7b450326e8242345776f3 3dd68c3bef19dbe75a3af0e5b3
07cff1b21e7500f5b9f8df775dc4ecaf6611d9ba8fc8cb0324 7f51d5bca10438b45eabb4
| 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.ne t!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?
|
| "Ben R. Bolton" <xb*******@hotmail.com> wrote in message
| news:OG**************@TK2MSFTNGP09.phx.gbl...
| > Thanks Mattias,
| >
| > I had hoped there was a compiler option, but at least there is a way.
| >
| > Ben
| >
| >
| > "Mattias Sjögren" <ma********************@mvps.org> wrote in message
| > news:%2****************@TK2MSFTNGP11.phx.gbl...
| > > 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.
| >
| >
|
|
|

Nov 15 '05 #10
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.
"Jeffrey Tan[MSFT]" <v-*****@online.microsoft.com> wrote in message
news:KO**************@cpmsftngxa06.phx.gbl...

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...b;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" <no****************@frontiernet.net>
| Newsgroups: microsoft.public.dotnet.languages.csharp
| References: <#o**************@TK2MSFTNGP09.phx.gbl>
<#p**************@TK2MSFTNGP11.phx.gbl>
<OG**************@TK2MSFTNGP09.phx.gbl>
| 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: <ho*****************@news01.roc.ny>
| X-Complaints-To: ab********@frontiernet.net
| X-Trace:
52616e646f6d4956a7c2f1d1725bf9c71a51cc963cf8af61d4 bf1cb8db7ce0b5f504894fa320 62d943d8f53fcbaf8e94930c7856e7b450326e8242345776f3 3dd68c3bef19dbe75a3af0e5b3 07cff1b21e7500f5b9f8df775dc4ecaf6611d9ba8fc8cb0324 7f51d5bca10438b45eabb4
| 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.ne t!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?
|
| "Ben R. Bolton" <xb*******@hotmail.com> wrote in message
| news:OG**************@TK2MSFTNGP09.phx.gbl...
| > Thanks Mattias,
| >
| > I had hoped there was a compiler option, but at least there is a way.
| >
| > Ben
| >
| >
| > "Mattias Sjögren" <ma********************@mvps.org> wrote in message
| > news:%2****************@TK2MSFTNGP11.phx.gbl...
| > > 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.
| >
| >
|
|
|

Nov 15 '05 #11
"Jeffrey Tan[MSFT]" <v-*****@online.microsoft.com> wrote in message
news:KO**************@cpmsftngxa06.phx.gbl...
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...b;en-us;315937

Is all that PAGE_GUARD stuff necessary in C#? I don't see the same behavior
with this example as the article shows:

class App {
private static long _Depth = 0;

private static void GoDeep() {
if ((++_Depth % 10000) == 0) System.Console.WriteLine("Depth is " +
_Depth.ToString());
GoDeep();
return;
}

public static void Main() {
for (int i = 0; i < 3; i++) {
try {
_Depth = 0;
System.Console.WriteLine();
GoDeep();
} catch (System.Exception Ex) {
System.Console.WriteLine(Ex.ToString());
}
}
return;
}
}

Depth is 10000
Depth is 20000
Depth is 30000
Depth is 40000
Depth is 50000
Depth is 60000
Depth is 70000
Depth is 80000
System.StackOverflowException: Exception of type
System.StackOverflowException was thrown.

Depth is 10000
Depth is 20000
Depth is 30000
Depth is 40000
Depth is 50000
Depth is 60000
Depth is 70000
Depth is 80000
System.StackOverflowException: Exception of type
System.StackOverflowException was thrown.

Depth is 10000
Depth is 20000
Depth is 30000
Depth is 40000
Depth is 50000
Depth is 60000
Depth is 70000
Depth is 80000
System.StackOverflowException: Exception of type
System.StackOverflowException was thrown.

-- Alan
Nov 15 '05 #12

Hi Ben,

Yes, it seems that the C# compiler does not have the option for change the
stack size.
But forturnately, we can change it with EditBin.exe
If you feel this uncomfortable, you can provide some suggestion to
Microsoft at this link:
http://register.microsoft.com/mswish/suggestion.asp
or you can mail to ms****@microsoft.com

Thanks for your understanding and information.

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.

--------------------
| Reply-To: "Ben R. Bolton" <xb*******@hotmail.com>
| From: "Ben R. Bolton" <xb*******@hotmail.com>
| References: <#o**************@TK2MSFTNGP09.phx.gbl>
<#p**************@TK2MSFTNGP11.phx.gbl>
| Subject: Re: Stack Size
| Date: Fri, 10 Oct 2003 15:46:20 -0700
| Lines: 27
| 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: <OG**************@TK2MSFTNGP09.phx.gbl>
| Newsgroups: microsoft.public.dotnet.languages.csharp
| NNTP-Posting-Host: 12-236-76-193.client.attbi.com 12.236.76.193
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP09.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.csharp:190668
| X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
|
| Thanks Mattias,
|
| I had hoped there was a compiler option, but at least there is a way.
|
| Ben
|
|
| "Mattias Sjögren" <ma********************@mvps.org> wrote in message
| news:%2****************@TK2MSFTNGP11.phx.gbl...
| > 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.
|
|
|

Nov 15 '05 #13

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" <no****************@frontiernet.net>
| Newsgroups: microsoft.public.dotnet.languages.csharp
| References: <#o**************@TK2MSFTNGP09.phx.gbl>
<#p**************@TK2MSFTNGP11.phx.gbl>
<OG**************@TK2MSFTNGP09.phx.gbl> <ho*****************@news01.roc.ny>
<KO**************@cpmsftngxa06.phx.gbl>
| 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: <Mx*****************@news02.roc.ny>
| X-Complaints-To: ab********@frontiernet.net
| X-Trace:
52616e646f6d495603120f292ac5ee1f96e15ff40a2890a76e e2e67f3baecd4d8941f5b87c8e
5d6e5833b660d4c3166e956bfc51cc3f300260143400fe3142 f055e9ae0f831dd0e6503ac8d4
e25f2ae19e5806bb4028cd1de6103810f79e0835853ba16c47 8c11dc9c644967267b9d7d
| 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!ne ws-feed01.roc.ny.frontiern
et.net!nntp.frontiernet.net!news02.roc.ny.POSTED!n ot-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.
|
|
| "Jeffrey Tan[MSFT]" <v-*****@online.microsoft.com> wrote in message
| news:KO**************@cpmsftngxa06.phx.gbl...
| >
| > 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...b;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" <no****************@frontiernet.net>
| > | Newsgroups: microsoft.public.dotnet.languages.csharp
| > | References: <#o**************@TK2MSFTNGP09.phx.gbl>
| > <#p**************@TK2MSFTNGP11.phx.gbl>
| > <OG**************@TK2MSFTNGP09.phx.gbl>
| > | 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: <ho*****************@news01.roc.ny>
| > | X-Complaints-To: ab********@frontiernet.net
| > | X-Trace:
| >
|
52616e646f6d4956a7c2f1d1725bf9c71a51cc963cf8af61d4 bf1cb8db7ce0b5f504894fa320
| >
|
62d943d8f53fcbaf8e94930c7856e7b450326e8242345776f3 3dd68c3bef19dbe75a3af0e5b3
| > 07cff1b21e7500f5b9f8df775dc4ecaf6611d9ba8fc8cb0324 7f51d5bca10438b45eabb4
| > | 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.ne t!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?
| > |
| > | "Ben R. Bolton" <xb*******@hotmail.com> wrote in message
| > | news:OG**************@TK2MSFTNGP09.phx.gbl...
| > | > Thanks Mattias,
| > | >
| > | > I had hoped there was a compiler option, but at least there is a
way.
| > | >
| > | > Ben
| > | >
| > | >
| > | > "Mattias Sjögren" <ma********************@mvps.org> wrote in message
| > | > news:%2****************@TK2MSFTNGP11.phx.gbl...
| > | > > 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.
| > | >
| > | >
| > |
| > |
| > |
| >
|
|
|

Nov 15 '05 #14

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: Kevin Grigorenko | last post by:
Hello, I couldn't find an obvious answer to this in the FAQ. My basic question, is: Is there any difference in allocating on the heap versus the stack? If heap or stack implementation is not...
10
by: Shuo Xiang | last post by:
Greetings: I know that variables declared on a stack definitely does not reside in heap space so there is only a very limited amount of stuff that you can store in the stack of a function. But...
2
by: Peter Oliphant | last post by:
Hey, is there a limit to the stack size? I realize of course there must be, but how is this determined/set? Or does it self adjust up to, say, available memory (and possibly virtual memory from...
9
by: Ajay | last post by:
Hi all, Can I know what is the stack space and heap space allocated by the compiler.Can i increase it or decrease it.if yes,pleae tell me theway to do it.Thanks in advance. Cheers, Ajay
5
by: sunny | last post by:
Hi All Is there any way to determine stack and heap size, during runtime. i.e can we predict stack overflow. etc
1
by: alfie27 | last post by:
I currently have a working program that is a stack that stores integers. Now i have to convert it to store strings instead of integers. I have been working on this for hours and just keep getting...
7
by: amit.atray | last post by:
Environement : Sun OS + gnu tools + sun studio (dbx etc) having some Old C-Code (ansi + KR Style) and code inspection shows some big size variable (auto) allocated (on stack) say for ex. char...
9
by: Jensen Somers | last post by:
Hi, Is it possible to change the stack size of a DLL from within the source code? When using threads you can specify the size of the stack you want the thread to use, but since my application...
3
by: mark4asp | last post by:
Stack of limited size containing unique items? Hi guys, How would I implement a stack of limited size containing unique items? For example. Suppose my stack has . I add 2 to it and it is now...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.