Home > Back-end >  Sqlite3_get_table memory like flying, for a great god help!!!!!!
Sqlite3_get_table memory like flying, for a great god help!!!!!!

Time:09-27

A running, memory fly old fast, support a move for the great god, can't play,
A rookie, you great god to explain in detail, very thank you!!!!!

 
Extern "C" int PASCAL EXPORT readb (int nRow [], int nColumn [], would be * sysbol)
{
AFX_MANAGE_STATE (AfxGetStaticModuleState ());
Sqlite3 * db=NULL;//declare the sqlite key structure pointer
Int result;//receive open file returns the success variables
Char * * dbResult=NULL;
Int my_age=0;
Char * * errmsg=NULL;//executing SQL statements error message receiving variables
Result=sqlite3_open (" c: \ \ Windows. Db ", & amp; Db);//open the sqlite3 database file, if the file does not exist, will create the sqlite3 database file
If (result!=SQLITE_OK)//whether the database open or create a successful, if successful result==0
{
Sqlite3_free (errmsg);
Sqlite3_close (db);
return NULL;
}
Int pSize1=WideCharToMultiByte (CP_OEMCP, 0, sysbol, wcslen (sysbol), NULL, 0, NULL, NULL);
If (pSize1==0)
{
return NULL;
}
Char * pC1=new char [pSize1 + 1];
WideCharToMultiByte (CP_OEMCP, 0, sysbol, wcslen (sysbol), pC1, pSize1, NULL, NULL);
PC1 [pSize1]='\ 0';

Char buffer [1024].
Sprintf (buffer, "select * from % s", pC1);

Result=sqlite3_get_table (db, buffer, & amp; DbResult, nRow, nColumn, errmsg);
If (result!=SQLITE_OK)//whether the database open or create a successful, if successful result==0
{
The delete [] pC1;
PC1=NULL;
Sqlite3_free (errmsg);
return NULL;
}
The delete [] pC1;
PC1=NULL;
Int index=0;
For (int I=0; i <(nRow [0] + 1) * nColumn [0]. I++)
{
The index=I - 1;
}
//char * t=dbResult [index];


My_age=atoi (dbResult [index]);
Sqlite3_free_table (dbResult);
Sqlite3_close (db);
Return my_age;
}

CodePudding user response:

Don't see the memory leak place ah, see sysbol variable is how to deal with

CodePudding user response:

reference 1st floor shihengzhen101 response:
didn't see the memory leak place ah, see sysbol variable is how to deal with the

Sysbol variables introduced from outside, and finally also need to handle it? How to deal with?

CodePudding user response:

refer to the second floor dnf1203398200 response:
Quote: refer to 1st floor shihengzhen101 response:

Don't see the memory leak place, see sysbol variable is how to deal with the

Sysbol variables introduced from outside, and finally also need to handle it? How to deal with?

This function is called repeatedly, or just call a special allowance of memory?

CodePudding user response:

Code function at the end of the day is not others to help you see or interpretation or comment; But by myself calm down and take a long enough time and energy to do it yourself step or set a breakpoint or step to perform to a certain intermediate result shows or written to the log file analysis step by step,
Remind: cow x teacher cannot replace the student understand and use the toilet!
Single step debugging and set breakpoint debugging (VS IDE compilation connection through later, press F10 or F11 key step, press Shift + F11 exit the current function; In a press F9 set breakpoints after press F5 execution stops at the breakpoint,) is one of the programmers must master the skills,

CodePudding user response:

reference shihengzhen101 reply: 3/f
Quote: refer to the second floor dnf1203398200 response:

Quote: refer to 1st floor shihengzhen101 response:

Don't see the memory leak place, see sysbol variable is how to deal with the

Sysbol variables introduced from outside, and finally also need to handle it? How to deal with?

This function is called repeatedly, or just call a special allowance of memory?

Call again and again

CodePudding user response:

This function will use sqlite3_table_free release the memory, you release?

CodePudding user response:

refer to 6th floor phenix2009 response:
this function use sqlite3_table_free release the memory, did you release?

Well, wrong and have released

CodePudding user response:

reference 5 floor dnf1203398200 reply:
Quote: refer to the third floor shihengzhen101 response:

Quote: refer to the second floor dnf1203398200 response:

Quote: refer to 1st floor shihengzhen101 response:

Don't see the memory leak place, see sysbol variable is how to deal with the

Sysbol variables introduced from outside, and finally also need to handle it? How to deal with?

This function is called repeatedly, or just call a special allowance of memory?

Repeated calls

Test memory growth rule first, looking call 20 times - how much memory is used in the call=10 times, every increase 10 times call and see if it is the same memory

CodePudding user response:

refer to 7th floor phenix2009 response:
Quote: refer to the sixth floor phenix2009 response:

This function will use sqlite3_table_free release the memory, you release?

Well, wrong and have released

The release of the release, the empty also have done, couldn't find where the problem

CodePudding user response:

refer to the eighth floor shihengzhen101 response:
Quote: refer to the fifth floor dnf1203398200 reply:

Quote: refer to the third floor shihengzhen101 response:

Quote: refer to the second floor dnf1203398200 response:

Quote: refer to 1st floor shihengzhen101 response:

Don't see the memory leak place, see sysbol variable is how to deal with the

Sysbol variables introduced from outside, and finally also need to handle it? How to deal with?

This function is called repeatedly, or just call a special allowance of memory?

Repeated calls

Test memory growth rule first, looking call 20 times - how much memory is used in the call=10 times, every increase 10 times call and see if it is growing the same memory

nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related