Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login




Remember Me
Forgot Password?
Join Us!

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Donate Today!

Do you enjoy these
technical forums?
Donate Today! Click Here

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.
Jobs from Indeed

Link To This Forum!

Partner Button
Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

TeeTeee (IS/IT--Management) (OP)
2 Sep 09 11:04
I am doing a tree search generation but I have an issue with the 2 functions below.

The functions are used to determine old nodes on the tree in order to stop further exploration.
Function "isOld" is used to detect if there are already explored nodes with the same state information as the current node. It calls function "addInfo" to retrieve the list of tokens for already explored nodes.

The issue here is: an exception error (first and second chance) occurs on line "return conjCodis;" that copies the node information to vector "codis".

"First chance exception 0xC0000005 ACCESS_VIOLATION occurred at 0x00427D77, write of address 0x00000008 at 0x00427D77First chance exception 0xC0000005 ACCESS_VIOLATION occurred at 0x00427D77, write of address 0x00000008 at 0x00427D77
and a Second chance exception on the same line."
The error points to the "copy construct" of the vector.

The code works pretty well for smaller trees but gives error on that line for longer time run (larger trees),  that takes more than 12 hours since I have tree generation problems that can take more than 2 days to run.
I used a 3rd party software to debug the code since it is not possible to run line debug for the time duration.

Your help would be greatly appreciated. Ideas on what to do and a better way to do this are welcomed.

CODE

vector<double> Tree::isOld(vector<TokenTree*> *tok, int trans, double codi) const
{
    vector<double> interseccio;

    vector<double> codis = conjPlaces.at(0)->addInfo(tok->at(0),codi);
    
    int i=0;
    interseccio=codis;
    for(i=1; i< tok->size(); i++)
    {
        codis = conjPlaces.at(i)->addInfo(tok->at(i),codi);

        int j = 0;
        vector<double>::iterator posIter = interseccio.begin();
        while(posIter!=interseccio.end())
        {
            vector<double>::iterator posicio = find(codis.begin(),codis.end(),*posIter);
            
            if(posicio==codis.end()){
                posIter = interseccio.erase(posIter++);
            }
            else
                ++posIter;                
        }
    }

    return interseccio;
}

CODE

vector<double> Place::addInfo(TokenTree *marca, double codi)
{
    vector<double> conjCodis;

    TreeToken tokAux = *marca;
    map<TreeToken,vector<double> ,ltstr>::iterator pos = marcatges.find(tokAux); //marcatges is the data structure that stores the tokens for each node.
    if(pos!=marcatges.end())
    {
        marca = const_cast<TreeToken*> (&((*pos).first));
        conjCodis = marcatges[*marca];

        marcatges[*marca].push_back(codi);
    }
    else
    {
        marcatges[*marca].push_back(codi);
    }
    return conjCodis;
}
xwb (Programmer)
3 Sep 09 1:53
Basically, the problem is returning a data structure on the stack.  This causes a lot of problems since the stack is more or less wiped on return.  Many books/articles wrongly advocate this technique.  It may work for small items but can cause crashes like the one you've seen.

Ways out: new the return item or make it static.
TeeTeee (IS/IT--Management) (OP)
3 Sep 09 10:10
Thanks for the insight. Actually, I have tried the static option and it crashes as well. I will give the "new" operator a shot. Will get back on the thread with the result.
TeeTeee (IS/IT--Management) (OP)
7 Sep 09 17:52
Thanks for the suggestion(new the return vector). It worked on that part but led to another access violation on the vector that is being modified within the loop (interseccio) in the function. I remodified the function Tree::isOld a little.

It returns the access violation error on line "vector<double>::iterator posIter = interseccio.begin();
"
(operation=,_UCopy, construct) after a long time run.

I checked to see if the issue was an empty vector but that didn't help.

CODE

if(!interseccio.empty())
    posIter = interseccio.begin();
else
    break;

Thanks for your help as usual.

CODE

void Tree::isOld(vector<TokenTree*> *tok, int trans, double codi, vector<double> interseccio) const
{
    vector<double> codis;
    interseccio = *(conjPlaces.at(0)->addInfo(tok->at(0),codi));
    
    int i=0;
    
    for(i=1; i< tok->size(); i++)
    {
        codis = *(conjPlaces.at(i)->addInfo(tok->at(i),codi));

        vector<double>::iterator posIter = interseccio.begin();
        while(posIter!=interseccio.end())
        {
            vector<double>::iterator posicio = find(codis.begin(),codis.end(),*posIter);
            
            if(posicio==codis.end()){
                posIter = interseccio.erase(posIter);
            }
            else
                ++posIter;                
        }
    }

}

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close