On 7/13/18, Bob Friesenhahn <[email protected]> wrote:
> On Fri, 13 Jul 2018, Martin Vystrčil wrote:
>
>> Hello everyone,
>>
>> I have a problem using sqlite in one of my project. When I create instance
>> of sqlite (sqlite_open) from main thread, memory consumption is in normal
>> (a few megabytes). But when I start sqlite from another thread,
>> immediately
>> around 70 - 80 MB of memory is allocated.
>>
>> Here is the smallest example, which can reproduce this problem. Link to
>> pastebin where source code is: https://pastebin.com/BkU3uMCb.
>
> I can not be bothered to visit such a site.
The OP's test program (with a bug fix, various whitespace changes, and
the addition of a call to sqlite3_memory_used()) is show below.
sqlite3_memory_used() reports no difference in memory allocation.
---------------------------------------------------------------------------------
#include <iostream>
#include <pthread.h>
#include <unistd.h>
#include <sqlite3.h>
using namespace std;
void *poll(void *data){
int rc = 0;
char *errMsg = 0;
sqlite3 *database;
int i;
rc = sqlite3_open(":memory:", &database);
if(rc != SQLITE_OK){
std::cout << "Cannot open memory database" << std::endl;
}
rc = sqlite3_exec(database, "create table if not exists xyz(id int,
descr text)",0,0,&errMsg);
if(rc != SQLITE_OK){
std::cout << "Cannot create table in SQLiteDB: " << errMsg << std::endl;
}
sqlite3_free(errMsg);
for(i=0; i<10; i++){
std::cout << "Thread safe: " << sqlite3_threadsafe() << std::endl;
rc = sqlite3_exec(database, "pragma page_count",0,0,&errMsg);
if(rc != SQLITE_OK){
std::cout << "Select page count from DB failed " << errMsg << std::endl;
sqlite3_free(errMsg);
}
std::cout << "memory used: " << sqlite3_memory_used() << std::endl;
usleep(100000);
std::cout << "Select from DBSQLite" << std::endl;
}
}
int main(int argc, char *argv[]){
if(argc > 1){
poll(NULL);
}else{
cout << "Starting of sqlite DB threaded mode ..." << endl;
pthread_t p;
if(pthread_create(&p, NULL, poll, NULL)){
cerr << "Error creating thread" << endl;
}
if(pthread_join(p, NULL)){
cerr << "Cannot join thread" << endl;
}
}
}
--
D. Richard Hipp
[email protected]
_______________________________________________
sqlite-users mailing list
[email protected]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users