Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.albasani.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Ian Collins Newsgroups: comp.lang.c++ Subject: Re: STL container and stack frame size Date: Tue, 09 Aug 2011 16:49:07 +1200 Lines: 28 Message-ID: <9absi3Fv2pU4@mid.individual.net> References: <6ebc4e08-8383-4284-982c-d84d1045266a@a2g2000prf.googlegroups.com> <4e3aaad2$0$2832$7b1e8fa0@news.nbl.fi> <4E40BAD2.9050002@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net nFJDhYzr2KOdb8mfEhhNBAPZMkQ96vv1eRRYJGWbbLzdKFWzDU Cancel-Lock: sha1:5ON8ulVYwcF1iJDDDfrAh2Hx6GA= User-Agent: Mozilla/5.0 (X11; U; SunOS i86pc; en-US; rv:1.9.2.9) Gecko/20101021 Lightning/1.0b2 Thunderbird/3.1.4 In-Reply-To: <4E40BAD2.9050002@gmail.com> Xref: x330-a1.tempe.blueboxinc.net comp.lang.c++:8574 On 08/ 9/11 04:42 PM, ittium wrote: > On 04-08-2011 PM 07:51, Juha Nieminen wrote: >> itt ium wrote: >>> if the vector is of big size, making a local variable will occupy lot >>> of stack space and may result in stack overflow. >> >> Nope. There's a very simple way of seeing how much stack space an >> object takes, namely: >> >> void foo() >> { >> std::vector v(10000); >> std::cout<< "v is taking"<< sizeof(v)<< " bytes of stack space.\n"; >> } >> >> Here it says "v is taking 12 bytes of stack space." >> >> The rest is allocated on the heap. > > This means, we really do not have any situation, where we should define > STL containers with pointers. Container with normal variables are > sufficient for most of the cases. Except where the object is "large", dynamically allocated, isn't copyable or you don't want to copy it... -- Ian Collins