Why does Visual C++ has a limited stack and heap allocation ...

文章推薦指數: 80 %
投票人數:10人

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,std::array,orsimilar. Cancel Save Intimetheprojectgrows,theignoranceofitsdevsitshows,withmanyaconvolutedfunction,itplungesintodeepcompunction,thepriceoffailureishigh,Washu'smirthisnigh. 21stCenturyMoose 13,459 March01,201211:35AM Regardingtheheapoption,it'simportanttoactuallyreadthedocumentationhereotherwiseyouhaveastrongriskofgettingsomeseriousmisunderstandingsaboutWindows.ThisisparticularlythecaseifcomingfromabackgroundofanotherOS-thereissometimesnodirectone-to-onemappingandifyourelyonwhatlooksorseemssimilaryoucanoftengodownanentirelywrongpath. InthiscasetherelevantMSDNpageishere:http://msdn.microsoft.com/en-us/library/ms810603.aspx Notethatfortheheap,thesizespecifiesinitialreserveandcommitsizes,notabsolutelimits: ...valuesspecifyingtheamountofreservedandcommittedspaceinitiallyneededbytheapplication.[/quote] Cancel Save Direct3Dhasneedofinstancing,butwedonot.WehaveplentyofglVertexAttribcalls. DarkRadeon Author 108 March01,201205:37PM Don'tallocatelargearraysonthestack.It'snotdesignedforthat.Usetheheap.new/delete.std::vector,std::array,orsimilar. Yes,Iknowthat,butthesourcefileswerenotwrittenbyme,Itestedonlythe"cost"ofthealgorithmthehad... Regardingtheheapoption,it'simportanttoactuallyreadthedocumentationhereotherwiseyouhaveastrongriskofgettingsomeseriousmisunderstandingsaboutWindows.ThisisparticularlythecaseifcomingfromabackgroundofanotherOS-thereissometimesnodirectone-to-onemappingandifyourelyonwhatlooksorseemssimilaryoucanoftengodownanentirelywrongpath. InthiscasetherelevantMSDNpageishere:http://msdn.microsof...y/ms810603.aspx Notethatfortheheap,thesizespecifiesinitialreserveandcommitsizes,notabsolutelimits: ...valuesspecifyingtheamountofreservedandcommittedspaceinitiallyneededbytheapplication. [/quote] Thankyouforthelink:D. Thecodewaswrittenfordifferentlinuxmachines(serversandadistributenet),soprobablytheauthordidnotcareaboutwindowsmemorymodel...Nowit'sallclear:) Thankyouguys. Cancel Save Share: Thistopicisclosedtonewreplies. Advertisement Advertisement PopularTopics What`sleft GDNetLounge Datatypediversity GeneralandGameplayProgramming takingatwillspaceinmemorycodedesign GeneralandGameplayProgramming Whatkindofnetworkbackendscope/magnitudecanIexpectforaCCG? NetworkingandMultiplayer SVOGIImplementationDetails GraphicsandGPUProgramming DX8toDX9 GraphicsandGPUProgramming Reticulatingsplines AboutGameDev.net TermsofService PrivacyPolicy ContactUs Copyright(c)1999-2021GameDev.net,LLC BacktoTop



請為這篇文章評分?