Project Home
Project Home
Source Code
Source Code
Documents
Documents
Wiki
Wiki
Discussion Forums
Discussions
Project Information
Project Info
Forum Topic - Weird crash: (4 Items)
   
Weird crash  
6.4.1 gcc 4.3.3.  Why could the following simple program SIGSEGV if compile with -N128k. I mean I don't see where stack 
operation are required.  Maybe a temporary object is used somewhere.  ForFun is 170k so 200k of stack should be enough 
but appartently after some test 501K of stack is used???

#include <vector>

class ForFun
{
public:
	char dummy[170000];
	
};

static std::vector<ForFun> vec;

int main (void)
{
	
	vec.resize(200);

	return 0;

}

Re: Weird crash  
Hi Mario,

debugging your example, I see  vector::resize( size_type _Newsize, _Ty _Val )  taking 340024 bytes of stack.

Looking into the "vector" header file, I think these come from 2 temporary ForFun objects being created in the course of
 resizing.

First, the method  vector::resize( size_type _Newsize )  does
   vector::resize( _Newsize, _Ty() );   [line 605]
which means the second argument (a ForFun in your case) will be created on the stack. 
The latter resize(), when expanding the vector, calls _Insert_n(), which itself uses a temporary variable:
   _Ty _Tmp = Val;    [line 1020]

These two together seem to perfectly explain your stack requirements.

Things like this always remind me what I hate about C++...

Cheers,
- Thomas
RE: Weird crash  

> -----Original Message-----
> From: Thomas Haupt [mailto:community-noreply@qnx.com]
> Sent: Sunday, August 23, 2009 5:04 AM
> To: general-toolchain
> Subject: Re: Weird crash
> 
> Hi Mario,
> 
> debugging your example, I see  vector::resize( size_type _Newsize, _Ty
> _Val )  taking 340024 bytes of stack.
> 
> Looking into the "vector" header file, I think these come from 2
> temporary ForFun objects being created in the course of resizing.
> 
> First, the method  vector::resize( size_type _Newsize )  does
>    vector::resize( _Newsize, _Ty() );   [line 605]
> which means the second argument (a ForFun in your case) will be created
> on the stack.
> The latter resize(), when expanding the vector, calls _Insert_n(),
> which itself uses a temporary variable:
>    _Ty _Tmp = Val;    [line 1020]
> 
> These two together seem to perfectly explain your stack requirements.
> 
> Things like this always remind me what I hate about C++...

I went through this same hate phase when going from assembler to C ;-)

> 
> Cheers,
> - Thomas
> 
> 
> 
> _______________________________________________
> 
> General
> http://community.qnx.com/sf/go/post36475
> 
Re: RE: Weird crash  
Hey Mario,

while objecting your implication, 
  I sure enjoyed your way to put it...

 *laugh*

- Thomas