473,769 Members | 1,748 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 25558
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)paldin o=at=exisconsul ting<dot>com

"Ben R. Bolton" <xb*******@hotm ail.com> wrote in message
news:%2******** ********@TK2MSF TNGP09.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************ **@exisconsulti ng.com> wrote
in message news:eO******** ******@TK2MSFTN GP09.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)paldin o=at=exisconsul ting<dot>com

"Ben R. Bolton" <xb*******@hotm ail.com> wrote in message
news:%2******** ********@TK2MSF TNGP09.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 NtQueryInformat ionThread 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*******@hotm ail.com>
| From: "Ben R. Bolton" <xb*******@hotm ail.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.publi c.dotnet.langua ges.csharp
| NNTP-Posting-Host: 12-236-76-193.client.attb i.com 12.236.76.193
| Path: cpmsftngxa06.ph x.gbl!TK2MSFTNG P08.phx.gbl!tk2 msftngp13.phx.g bl
| Xref: cpmsftngxa06.ph x.gbl microsoft.publi c.dotnet.langua ges.csharp:1896 51
| X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.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************ **@exisconsulti ng.com>
wrote
| in message news:eO******** ******@TK2MSFTN GP09.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)paldin o=at=exisconsul ting<dot>com
| >
| > "Ben R. Bolton" <xb*******@hotm ail.com> wrote in message
| > news:%2******** ********@TK2MSF TNGP09.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.o rg> wrote in message
news:%2******** ********@TK2MSF TNGP11.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("Dept h is " +
_Depth.ToString ());
GoDeep();
return;
}

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


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

Unhandled Exception: StackOverflowEx ception.

editbin /stack:1000000,1 000 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: StackOverflowEx ception.
-- 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.publi c.dotnet.langua ges.csharp
| NNTP-Posting-Host: host-13-19-220-24.midco.net 24.220.19.13
| Path: cpmsftngxa06.ph x.gbl!TK2MSFTNG P08.phx.gbl!TK2 MSFTNGP09.phx.g bl
| Xref: cpmsftngxa06.ph x.gbl microsoft.publi c.dotnet.langua ges.csharp:1903 07
| X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.csharp
|
| "Mattias Sjögren" <ma************ ********@mvps.o rg> wrote in message
| news:%2******** ********@TK2MSF TNGP11.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("Dept h is " +
| _Depth.ToString ());
| GoDeep();
| return;
| }
|
| public static void Main() {
| try {
| GoDeep();
| } finally {
| }
| return;
| }
| }
|
|
|
|
| editbin /stack:100000,10 00 q.exe
| Depth is 10000
| Depth is 20000
|
| Unhandled Exception: StackOverflowEx ception.
|
| editbin /stack:1000000,1 000 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: StackOverflowEx ception.
|
|
| -- 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.o rg> wrote in message
news:%2******** ********@TK2MSF TNGP11.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.StackOv erflowException ' 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*******@hotm ail.com> wrote in message
news:OG******** ******@TK2MSFTN GP09.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.o rg> wrote in message
news:%2******** ********@TK2MSF TNGP11.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************ ****@frontierne t.net>
| Newsgroups: microsoft.publi c.dotnet.langua ges.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.ro c.ny>
| X-Complaints-To: ab********@fron tiernet.net
| X-Trace:
52616e646f6d495 6a7c2f1d1725bf9 c71a51cc963cf8a f61d4bf1cb8db7c e0b5f504894fa32 0
62d943d8f53fcba f8e94930c7856e7 b450326e8242345 776f33dd68c3bef 19dbe75a3af0e5b 3
07cff1b21e7500f 5b9f8df775dc4ec af6611d9ba8fc8c b03247f51d5bca1 0438b45eabb4
| 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.ph x.gbl!TK2MSFTNG P08.phx.gbl!new s-out.cwix.com!ne wsfeed.cwix.co
m!prodigy.com!r ip!news.webusen et.com!peer01.c ox.net!cox.net! newshosting.com !
news-xfer2.atl.newsh osting.com!news-feed01.roc.ny.f rontiernet.net! nntp.front
iernet.net!news 01.roc.ny.POSTE D!not-for-mail
| Xref: cpmsftngxa06.ph x.gbl microsoft.publi c.dotnet.langua ges.csharp:1907 09
| X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.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.StackOv erflowException ' 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*******@hotm ail.com> wrote in message
| news:OG******** ******@TK2MSFTN GP09.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.o rg> wrote in message
| > news:%2******** ********@TK2MSF TNGP11.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

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

Similar topics

14
30099
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 part of the standard, then just disregard this question. Here's some questions I'm confused about, and if you can add anything else, please do so! Is the stack limited for each program?
10
8346
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 what about the global space? Is that the same as the heap space or is that still a form of special stack? Because once I've seen someone declare a 1 megabyte char array in global space like this: char s;
2
1880
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 hard drives)? My current project can be set to be from very-stack-intensive to not-so-stack-intensive. The more stack-intensive it is the faster the code will run, but it can conceivable want to put huge amounts of info on the stack (there are...
9
7330
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
37162
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
4221
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 errors of all kinds. I have decided to start from scratch. Any suggestions someone can give me would be greatly appreciated!! Here is the current code: #include <iostream> using std::cout; using std::cin; #include <cstring> using std::strcpy;
7
22049
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 a; (this type of code and other complex mallc/free etc is used frequently and total approx 450 files, each file is of approx/avg 1000 line,
9
8735
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 doesn't use threads I'm looking for another solution. Source code I haven't written but which I use creates a structure containing 4 double arrays of almost 30k. I know this is big but it's required and I cannot change anything about that.
3
8325
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 . Now I want to add 5 to the unique item stack so it should now be: . The item added is pulled from the stack, then pushed. The stack should also have a maximum size of 4 items. I add 4 and 7
0
9589
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10212
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10047
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9995
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6674
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5304
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5447
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3563
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.