This is the mail archive of the
cygwin
mailing list for the Cygwin project.
Re: Trouble with std::vector in g++
- From: "Gerrit P. Haase" <freeweb at nyckelpiga dot de>
- To: Luke Stras <stras at utias dot utoronto dot ca>
- Cc: cygwin at cygwin dot com
- Date: Wed, 25 Aug 2004 19:16:45 +0200
- Subject: Re: Trouble with std::vector in g++
- Organization: Esse keine toten Tiere
- References: <20040825164918.GF9503@arrow.utias.utoronto.ca>
- Reply-to: "Gerrit P. Haase" <freeweb at nyckelpiga dot de>
Luke wrote:
> I am having some trouble with the std::vector class in g++ 3.3.3. If I
> compile the following program and run it, it segfaults in the call to
> push_back; reducing the array in Solution to 512*1024 makes the code run
> OK.
> If I compile it with g++ 3.2.1 under Linux, the program runs fine.
> Is it just my misunderstanding of how the STL works, or is there a
> compiler/library problm here?
> vvv begin code vvv
> #include <vector>
> class Solution {
> public:
> char se[1024*1024];
> };
> class Element {
> public:
> Solution s;
> };
> typedef std::vector<Element> element_list_t;
> class Mesh {
> public:
> element_list_t elements;
> };
> int
> main()
> {
> Mesh *mesh = new Mesh;
> Element el;
> mesh->elements.push_back(el);
> return 0;
> }
> ^^^ end code sample ^^^
> compile with:
> $ g++ -Wall -o etest etest.cc
> $ ./etest
> Segmentation fault (core dumped)
Increase the stack:
g++ -Wall -Wl,--stack=8000000 -o etest etest.cc
This works for me with gcc-3.4.1(tm). The default stack for Cygwin
executables is 2MB which seems to be too small for your program.
Gerrit
--
=^..^= http://nyckelpiga.de/donate.html
--
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Problem reports: http://cygwin.com/problems.html
Documentation: http://cygwin.com/docs.html
FAQ: http://cygwin.com/faq/