This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Optimizer Problem
- To: egcs-bugs at cygnus dot com
- Subject: Optimizer Problem
- From: asteil at tes dot zv dot mmo dot de (Andreas Steil - TEP (Tel. 3281))
- Date: Mon, 11 May 1998 15:38:23 +0200
- Cc: egcs at cygnus dot com, wines at ifn dot et dot tu-dresden dot de, andreas dot steil at d2privat dot de
Hello,
I am working with gcc version egcs-2.90.23 980102 (egcs-1.0.1 release) running on
Solaris 2.5.1.
Working with the stl shipped with the above release, I encountered a problem
which I summarized in a very small program, cf. attachment or annex to this mail,
which reproduces the problem using the optimizer.
Compiling said program with
g++ -Wall -O2 stl_mem.cc
results in the error message
/usr/local/gnu/sol2.5.egcs/lib/g++/stl_construct.h: In function `void
destroy<vector<vector<int,__default_alloc_template<false,0> >,__default_alloc_template<false,0> > *>(class
vector<vector<int,__default_alloc_template<false,0> >,__default_alloc_template<false,0> > *, class
vector<vector<int,__default_alloc_template<false,0> >,__default_alloc_template<false,0> > *)':
/usr/local/gnu/sol2.5.egcs/lib/g++/stl_construct.h:66: virtual memory exhausted
Compiling the program without optimizer, i.e. without -O2, everything works perfectly;
a.out says:
The element [0][0][4]: 400,
as I expected.
Could you please help me and tell me whether the above error message is
a consequence of
1) a bug or
2) my wrong understanding on the application of the stl ;-( .
In the first case, please let me know how the bug can be fixed.
In the second case, please help me to refine my knowledge by briefly explaining me where
I went wrong and by changing the program in a way that it can be compiled with the option -O2.
In either case, I thank you very much in advance for your help.
Desperately seeking help,
yours,
Andreas
////////////////////////////////////////////////////////////////////////////////////////////
#include <stl.h>
#include <iostream.h>
int main (char* argc, char* argv[]) {
vector< vector< vector<int> > > my3DVector;
vector< vector<int> > my2DVector;
vector< int > my1DVector;
for ( int i = 0; i < 10; i++ ) my1DVector.push_back(100*i);
my2DVector.push_back(my1DVector);
my3DVector.push_back(my2DVector);
cout << " The element [0][0][4]: " << my3DVector[0][0][4] << endl;
}
#include <stl.h>
#include <iostream.h>
int main (char* argc, char* argv[]) {
vector< vector< vector<int> > > my3DVector;
vector< vector<int> > my2DVector;
vector< int > my1DVector;
for ( int i = 0; i < 10; i++ ) my1DVector.push_back(100*i);
my2DVector.push_back(my1DVector);
my3DVector.push_back(my2DVector);
cout << " The element [1][1][5]: " << my3DVector[0][0][4] << endl;
}