Why does Visual C++ has a limited stack and heap allocation ...
文章推薦指數: 80 %
In visual studio, on the linker option there are bot Stack and Heap reserve Size, both are set to 1MB as default.
AllContent
Blogs
Forums
News
Tutorials
LogIn
SignUp
Login
Username/Email
Password
Rememberme
Forgotpassword?
Login
or
Don'thaveaGameDev.netaccount?Signup
Forgotyourpassword?
EmailAddress
ResetPassword
Pleasecontactusifyouhaveanytroubleresettingyourpassword.
Home
Blogs
Careers
Careers
Forums
News
Portfolios
Projects
Tutorials
New?Learnaboutgamedevelopment
FollowUs
ChatintheGameDev.netDiscord!
BacktoGeneralandGameplayProgramming
WhydoesVisualC++hasalimitedstackandheapallocationdimension(1MiBasdefault)?
GeneralandGameplayProgramming
Programming
Startedby
DarkRadeon
February29,201206:17PM
7
comments,lastbyDarkRadeon10 years,5 monthsago
Advertisement
DarkRadeon
Author
108
February29,201206:17PM
Yes,Ionlylearnittoday,afteranentireafternoonspentwithseveralalgorithmsanddatastructuresC++samplesgettingcrashonWindowsforunknownreason-.-
Oneanswercouldbe:"foroptimizationkindastuffs..."
...
Imean,areyoukiddingmeMicrosoft?
Whydon'tyougivemeasimplemessagelike"Heyyoudumb-ass,hereyoucannotallocatemorethen1MiBontostackoryoumustchangethelinkeroption"?
Onseverallinuxmachinesallworkedfine,evenwithverylargestackallocations(morethan100MB),sowhatistherealreason?
Iknowthatgenerallyhavingareallybigstackisnotsocommon(anagoodidea),butwhyMicrosoftsetalotoflimitationwithoutwarningtheuser?ç___ç
edit:wow,samelimitationfortheheap:|
Cancel
Save
fastcall22
10,909
February29,201207:36PM
gettingcrashonWindowsforunknownreason
Wereyounotdebugging?Ifyouwere,youwouldhavereceiveda"StackOverflow"exception...
Cancel
Save
DarkRadeon
Author
108
February29,201207:38PM
[quotename='Alessio89'timestamp='1330539443'post='4917874']
gettingcrashonWindowsforunknownreason
Wereyounotdebugging?Ifyouwere,youwouldhavereceiveda"StackOverflow"exception...
[/quote]
becauseIuseddifferentIDEsandcompilersIwas"testing"onmanymachines..andonlyonWindowsPCsIhadthatproblemandIknewthatthecodewasright,soIdidn'tthinkaboutdebugging..
Cancel
Save
Antheus
2,410
February29,201208:30PM
sowhatistherealreason?[/quote]
StackislimitedtoavoidresourceexhaustionbyOS.Stackisnon-pageablememoryandapplicationscouldexhaustRAMtooquickly.
wow,samelimitationfortheheap:|[/quote]
Huh?Heapisn'tlimitedbeyondwhatOScanallocate.It'sdefinitelynotlimitedto1MB.Largeallocations(1GB+)howevermayfail,butthat'snotuniquetoWindows.
onlyonWindowsPCsIhadthatproblem[/quote]
Unlessyoumanuallyspecificstacksizeonotherplatforms,thelimitationsarethesame.it'salsoperfectlypossibletosimplysmashthestackwithoutcrashing,sonothavingproblemselsewheremightbejustusualundefinedbehavior.
I'mguessingithastodowithsomethingelse,similartothis:
intbar[1024*1024*1024];
intmain(){
intfoo[1024*1024*1024];
}
barmaygetallocatedinsideoneofexesections,sosizeconstraintsagainbecomeaproblem.Notsureifandwhatkindoflimitsthereare.
fooisobviouslytoolargeforstack.
Applicationlikethatwouldrequire1GBofphysicalRAMand2GBofaddressspaceatminimumwhichisproblematicingeneralcase,butnotnecessarilyimpossibletoachieve,justtakesafewlinkerswitches.
OtherOSeshavesameconstraints.
Cancel
Save
DarkRadeon
Author
108
February29,201208:57PM
StackislimitedtoavoidresourceexhaustionbyOS.Stackisnon-pageablememoryandapplicationscouldexhaustRAMtooquickly.
IknowthatbuttheapplicationsItestedneverhadbigallocationmemory(topically10-100MB)
Huh?Heapisn'tlimitedbeyondwhatOScanallocate.It'sdefinitelynotlimitedto1MB.Largeallocations(1GB+)howevermayfail,butthat'snotuniquetoWindows.
Invisualstudio,onthelinkeroptiontherearebotStackandHeapreserveSize,botharesetto1MBasdefault.
Unlessyoumanuallyspecificstacksizeonotherplatforms,thelimitationsarethesame.it'salsoperfectlypossibletosimplysmashthestackwithoutcrashing,sonothavingproblemselsewheremightbejustusualundefinedbehavior.
Ialsoworkedwithsomelinuxserver,whereIcouldn'ttouchnothingexceptsubmittingsourcecode,theserverhadthetasktocompileitandrunitsendingtomeresultliketimeexecutiontimecompilationetc..
I'mguessingithastodowithsomethingelse,similartothis:
intbar[1024*1024*1024];
intmain(){
intfoo[1024*1024*1024];
}
barmaygetallocatedinsideoneofexesections,sosizeconstraintsagainbecomeaproblem.Notsureifandwhatkindoflimitsthereare.
fooisobviouslytoolargeforstack.
Thebiggestsingle"object"Ihadinthevariousprogramswerearraysofonmillionintegers,likeinta[1000000]andonbothwindowsandlinuxanintshouldbe4bytes,so4millionsbytes,~3.8MB,notabigproblemformachinesequippedwithatleast4GBRAM..
Applicationlikethatwouldrequire1GBofphysicalRAMand2GBofaddressspaceatminimumwhichisproblematicingeneralcase,butnotnecessarilyimpossibletoachieve,justtakesafewlinkerswitches.
OtherOSeshavesameconstraints.
I'mactuallyabstainfromC++,butInoticethatmakingglobalorstaticthosearraysolvethatkindofproblem...
MaybeIshouldseeagaintheC++memoryallocationmodelxD
Cancel
Save
DarkRadeon
Author
108
February29,201210:36PM
mmmOK,nowIunderstandthatthestackreservesizeisexpressedinbyteandnotintMB...nowwiththecorrectvalueitworksperfectly..
Cancel
Save
Washu
7,836
February29,201210:43PM
Don'tallocatelargearraysonthestack.It'snotdesignedforthat.Usetheheap.new/delete.std::vector
延伸文章資訊
- 1VS 2017 C++Compiler runs out of heap space
Both 32-bit and 64-bit configurations compile and eventually run out of heap space. Visual Studio...
- 2cpp-docs/heap-set-heap-size.md at main - GitHub
Open the project's Property Pages dialog box. For details, see Set C++ compiler and build propert...
- 3Visual Studio 16.7 reporting compiler is out of heap space ...
When compiling a Visual C++ project that successfully compiled under Visual Studio MSVC 16.6 yest...
- 4How to increase the maximum memory allocated on the stack ...
- 5Heap Views in Visual Studio - Mark Downie
The Diagnostic Tool is at its best when you want to compare things over time, like say when memor...