I am using SQLite3 in C++, I found the opening time of sqlite seems unstable at the first time (by that I mean the time to open windows and open the db at the first time). It takes a long time on 50M db, about 10s in windows, and vary on different times.
Has any one met the same problem?
I am writing a desktop application in windows, so the opening speed is really important for me. Thanks in advance
void OpenDB(const CString& strPath)
{
int nRet;
#if defined(_UNICODE) || defined(UNICODE)
nRet = sqlite3_open16(szFile, &mpDB); // not tested under window 98
#else // For Ansi Version
//****- Added by Begemot szFile must be in unicode- 23/03/06 11:04 - ****
OSVERSIONINFOEX osvi;
ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX));
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
GetVersionEx((OSVERSIONINFO *) &osvi);
if ( osvi.dwMajorVersion == 5)
{
WCHAR pMultiByteStr[MAX_PATH+1];
MultiByteToWideChar( CP_ACP, 0, szFile,
_tcslen(szFile)+1, pMultiByteStr,
sizeof(pMultiByteStr)/sizeof(pMultiByteStr[0]) );
nRet = sqlite3_open16(pMultiByteStr, &mpDB);
}
else
nRet = sqlite3_open(szFile,&mpDB);
#endif
//*************************
if (nRet != SQLITE_OK)
{
LPCTSTR szError = (LPCTSTR) _sqlite3_errmsg(mpDB);
throw CppSQLite3Exception(nRet, (LPTSTR)szError, DONT_DELETE_MSG);
}
setBusyTimeout(mnBusyTimeoutMs);
}
At first, I thought is was a cache problem, I thought it was becase of the random access of sqlite for my indexes on the disk which cause such a long time at the first start(restart windows). So I added the following code before it:
BOOL CQFilePro::PreLoad(const CString& strPath)
{
boost::shared_array<BYTE> temp = boost::shared_array<BYTE>(new BYTE[PRE_LOAD_BUFFER_LENGTH]);
int nReadLength;
try {
CFile file;
if (file.Open(strPath, CFile::modeRead) == FALSE)
{
return FALSE;
}
do {
nReadLength = file.Read(temp.get(), PRE_LOAD_BUFFER_LENGTH);
} while (nReadLength == PRE_LOAD_BUFFER_LENGTH);
file.Close();
}
catch(...) {
}
return TRUE;
}
CString strDBPath = _T("XXXX");
preload(strDBPath);
Opendb(strDBPath);
however this code makes no difference.