MySQL Forums
Forum List  »  Source, Builds, Binaries

bad alloc problem using mysql lib
Posted by: Antony Brisson-Gironne
Date: March 30, 2010 12:05PM

I'm trying to develop some kind of hockey simulator but I'm having this weird allocation memory error the second time it's getting called. I have about the same function for another query (but with players) and it works flawlessly. I'm trying to return my rows via a mysql_row vector and I'm not sure if it's a good idea. Since I don't really know how mysql_store_result works in the background and how vectors are bing handled I was wondering if anyone has an idea on how it works and what's the best solution for me... Here is my function

vector<MYSQL_ROW> Database::get_goalers(string team){

vector<MYSQL_ROW> goalers;
vector<MYSQL_ROW>::iterator it;

MYSQL_RES *result;
MYSQL_ROW row;

if (connection == NULL)
cout << mysql_error(&mysql) << endl;
else
{

string query = "SELECT * FROM goalies WHERE Team = '" + team + "' ORDER BY OV";

mysql_query(connection, query.c_str()); //query the database
result = mysql_store_result(connection);

if (result == NULL)
{
cout << mysql_error(&mysql) << endl;
}
else
{
it = goalers.begin();
while ((row = mysql_fetch_row(result)))
{
if (row != NULL)
{
//cout << row[0] << " and " << row[1] << endl ;
it = goalers.insert(it, row); //ça plante ici... sait pas pourquoi... 2ieme équipe seulement, 3ieme enregistrement

}
}
}
//mysql_free_result(result);
}

return goalers;
}

And here is the error I get...

/*
* If this ASSERT fails, a bad pointer has been passed in. It may be
* totally bogus, or it may have been allocated from another heap.
* The pointer MUST come from the 'local' heap.
*/
_ASSERTE(_CrtIsValidHeapPointer(pUserData));


If I use mysql_use_result it doesnt work and if I try to free the result after adding them to my vector the returned value gets erased... I guess the returned result is some kind of reference since I can't free the first result after storing it in my vector. What I need is to store those values somewhere in my ram during the whole game simulation, then after free it before simulating the next game.

Any idea?

Options: ReplyQuote


Subject
Views
Written By
Posted
bad alloc problem using mysql lib
3315
March 30, 2010 12:05PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.