Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > std::map<> problem

Reply
Thread Tools

std::map<> problem

 
 
jski
Guest
Posts: n/a
 
      12-14-2012
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[i] >> beta[i] >> Force[i][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[i], beta[i],
Force[i][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
 
Reply With Quote
 
 
 
 
jski
Guest
Posts: n/a
 
      12-14-2012
On Dec 14, 6:10*pm, jski <(E-Mail Removed)> 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[i] >> beta[i] >> Force[i][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[i], beta[i],
> Force[i][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[i] >> beta[i] >> Force[i][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
 
Reply With Quote
 
 
 
 
Ian Collins
Guest
Posts: n/a
 
      12-14-2012
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[i] >> beta[i] >> Force[i][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[i], beta[i],
> Force[i][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
 
Reply With Quote
 
jski
Guest
Posts: n/a
 
      12-15-2012
On Dec 14, 6:42*pm, jski <(E-Mail Removed)> wrote:
> On Dec 14, 6:10*pm, jski <(E-Mail Removed)> 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[i] >> beta[i] >> Force[i][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[i], beta[i],
> > Force[i][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[i] >> beta[i] >> Force[i][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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem problem problem :( Need Help Mike ASP General 2 05-11-2004 08:36 AM



Advertisments