std::map<> problem

J

jski

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
 
J

jski

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//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
 
I

Ian Collins

jski said:
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?
 
J

jski

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?

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top