std::map<> problem

Discussion in 'C++' started by jski, Dec 14, 2012.

  1. jski

    jski Guest

    First:
    $ g++ --version
    g++ (GCC) 4.7.2 20120921 (Red Hat 4.7.2-2)

    I'm using the following declarations:

    struct point
    {
    double alpha, beta;
    double Force;

    point( double a, double b, double f ) : alpha(a), beta(b), Force(f)
    {}
    };

    struct node
    {
    int XYZ;
    vector<point> pt;
    };

    map<int, node> AeroDOF2;

    I'm looping thru a file to populate AeroDOF2:

    for( i=1; i<=AlphaBetaBlocks; ++i)
    for( j=1; j<=No_DOF; ++j )
    {
    AEROfile >> AeroDOF[j] >> alpha >> beta >> Force[j] >>
    XYZ[j] >> X[j] >> Y[j] >> Z[j] >> Node[j];
    AeroDOF2[ AeroDOF[j] ].XYZ = XYZ[j];
    AeroDOF2[ AeroDOF[j] ].pt.push_back( point( alpha, beta,
    Force[j] ) );
    }

    After successful looping for awhile, I get to j == 110 and die with a
    SEG FAULT at:
    AeroDOF2[ AeroDOF[j] ].XYZ = XYZ[j];
    where:
    AeroDOF[110] ==415 and XYZ[110] == 1 (according to GDB)

    Is there a problem with my use of the STL map template?

    ---John
     
    jski, Dec 14, 2012
    #1
    1. Advertising

  2. jski

    jski Guest

    On Dec 14, 6:10 pm, jski <> wrote:
    > First:
    > $ g++ --version
    > g++ (GCC) 4.7.2 20120921 (Red Hat 4.7.2-2)
    >
    > I'm using the following declarations:
    >
    > struct point
    > {
    >   double alpha, beta;
    >   double Force;
    >
    >   point( double a, double b, double f ) : alpha(a), beta(b), Force(f)
    > {}
    >
    > };
    >
    > struct node
    > {
    >   int XYZ;
    >   vector<point> pt;
    >
    > };
    >
    > map<int, node> AeroDOF2;
    >
    > I'm looping thru a file to populate AeroDOF2:
    >
    >   for( i=1; i<=AlphaBetaBlocks; ++i)
    >     for( j=1; j<=No_DOF; ++j )
    >       {
    >         AEROfile >> AeroDOF[j] >> alpha >> beta >> Force[j] >>
    > XYZ[j] >> X[j] >> Y[j] >> Z[j] >> Node[j];
    >         AeroDOF2[ AeroDOF[j] ].XYZ = XYZ[j];
    >         AeroDOF2[ AeroDOF[j] ].pt.push_back( point( alpha, beta,
    > Force[j] ) );
    >       }
    >
    > After successful looping for awhile, I get to j == 110 and die with a
    > SEG FAULT at:
    >         AeroDOF2[ AeroDOF[j] ].XYZ = XYZ[j];
    > where:
    >         AeroDOF[110] ==415 and XYZ[110] == 1 (according to GDB)
    >
    > Is there a problem with my use of the STL map template?
    >
    > ---John


    I replaced the loop with:

    for( i=1; i<=AlphaBetaBlocks; ++i)
    for( j=1; j<=No_DOF; ++j )
    {
    AEROfile >> AeroDOF >> alpha >> beta >> Force >> XYZ >> X >> Y >> Z
    >> N;

    //AEROfile >> AeroDOF[j] >> alpha >> beta >> Force[j] >>
    XYZ[j] >> X[j] >> Y[j] >> Z[j] >> NNode[j];
    AeroDOF2[ AeroDOF ].XYZ = XYZ;
    AeroDOF2[ AeroDOF ].pt.push_back( point( alpha, beta, Force ) );
    }

    Just using local variables to store the data read from the file - NOT
    the arrays and it appears to work. Not sure why?

    ---John
     
    jski, Dec 14, 2012
    #2
    1. Advertising

  3. jski

    Ian Collins Guest

    jski wrote:
    > First:
    > $ g++ --version
    > g++ (GCC) 4.7.2 20120921 (Red Hat 4.7.2-2)
    >
    > I'm using the following declarations:
    >
    > struct point
    > {
    > double alpha, beta;
    > double Force;
    >
    > point( double a, double b, double f ) : alpha(a), beta(b), Force(f)
    > {}
    > };
    >
    > struct node
    > {
    > int XYZ;
    > vector<point> pt;
    > };


    General comment: Mixing naming styles (caps, mixed caps etc.) for the
    same thing is a bad idea!

    > map<int, node> AeroDOF2;
    >
    > I'm looping thru a file to populate AeroDOF2:
    >
    > for( i=1; i<=AlphaBetaBlocks; ++i)
    > for( j=1; j<=No_DOF; ++j )
    > {
    > AEROfile >> AeroDOF[j] >> alpha >> beta >> Force[j] >>
    > XYZ[j] >> X[j] >> Y[j] >> Z[j] >> Node[j];


    Do you know if these arrays are in bounds?

    > AeroDOF2[ AeroDOF[j] ].XYZ = XYZ[j];
    > AeroDOF2[ AeroDOF[j] ].pt.push_back( point( alpha, beta,
    > Force[j] ) );
    > }
    >
    > After successful looping for awhile, I get to j == 110 and die with a
    > SEG FAULT at:
    > AeroDOF2[ AeroDOF[j] ].XYZ = XYZ[j];
    > where:
    > AeroDOF[110] ==415 and XYZ[110] == 1 (according to GDB)


    Where does the fault occur?

    Have you tried valgrind?

    --
    Ian Collins
     
    Ian Collins, Dec 14, 2012
    #3
  4. jski

    jski Guest

    On Dec 14, 6:42 pm, jski <> wrote:
    > On Dec 14, 6:10 pm, jski <> wrote:
    >
    >
    >
    >
    >
    >
    >
    >
    >
    > > First:
    > > $ g++ --version
    > > g++ (GCC) 4.7.2 20120921 (Red Hat 4.7.2-2)

    >
    > > I'm using the following declarations:

    >
    > > struct point
    > > {
    > >   double alpha, beta;
    > >   double Force;

    >
    > >   point( double a, double b, double f ) : alpha(a), beta(b), Force(f)
    > > {}

    >
    > > };

    >
    > > struct node
    > > {
    > >   int XYZ;
    > >   vector<point> pt;

    >
    > > };

    >
    > > map<int, node> AeroDOF2;

    >
    > > I'm looping thru a file to populate AeroDOF2:

    >
    > >   for( i=1; i<=AlphaBetaBlocks; ++i)
    > >     for( j=1; j<=No_DOF; ++j )
    > >       {
    > >         AEROfile >> AeroDOF[j] >> alpha >> beta >> Force[j] >>
    > > XYZ[j] >> X[j] >> Y[j] >> Z[j] >> Node[j];
    > >         AeroDOF2[ AeroDOF[j] ].XYZ = XYZ[j];
    > >         AeroDOF2[ AeroDOF[j] ].pt.push_back( point( alpha, beta,
    > > Force[j] ) );
    > >       }

    >
    > > After successful looping for awhile, I get to j == 110 and die witha
    > > SEG FAULT at:
    > >         AeroDOF2[ AeroDOF[j] ].XYZ = XYZ[j];
    > > where:
    > >         AeroDOF[110] ==415 and XYZ[110] == 1 (accordingto GDB)

    >
    > > Is there a problem with my use of the STL map template?

    >
    > > ---John

    >
    > I replaced the loop with:
    >
    >   for( i=1; i<=AlphaBetaBlocks; ++i)
    >     for( j=1; j<=No_DOF; ++j )
    >       {
    >         AEROfile >> AeroDOF >> alpha >> beta >> Force >> XYZ >> X>> Y >> Z>> N;
    >
    >         //AEROfile >> AeroDOF[j] >> alpha >> beta >> Force[j] >>
    > XYZ[j] >> X[j] >> Y[j] >> Z[j] >> NNode[j];
    >         AeroDOF2[ AeroDOF ].XYZ = XYZ;
    >         AeroDOF2[ AeroDOF ].pt.push_back( point( alpha, beta, Force ) );
    >       }
    >
    > Just using local variables to store the data read from the file - NOT
    > the arrays and it appears to work.  Not sure why?
    >
    > ---John


    Found an array, AeroDOF, that was dimensioned with too small a value.
     
    jski, Dec 15, 2012
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Peter Jansson
    Replies:
    5
    Views:
    6,318
    Ivan Vecerina
    Mar 17, 2005
  2. Replies:
    1
    Views:
    428
    red floyd
    Dec 21, 2008
  3. Thomas J. Gritzan
    Replies:
    6
    Views:
    1,025
    James Kanze
    Dec 22, 2008
  4. James Kanze
    Replies:
    0
    Views:
    2,006
    James Kanze
    Dec 21, 2008
  5. tombert
    Replies:
    3
    Views:
    651
    Juha Nieminen
    Aug 25, 2012
Loading...

Share This Page