Note that there are some explanatory texts on larger screens.

plurals
  1. POIncreasing memory usage in sqlite3?
    primarykey
    data
    text
    <p>I've written a console app which receives events via boost::interprocess memory and dumps the info into an sqlite3 database. While running the app I've noticed that, in the Windows task manager, the memory usage was cyclically increasing every... 30s-1min. This led me to believe that the problem lies within the main loop in which I execute my SQL. I've added some monitoring and apparently the sqlite3_memory_usage returns increasing results every couple loop iterations.</p> <p>Can somebody tell me what am I doing wrong? Am I missing something I should de-allocate ?</p> <p>Here are 2 strings I use to generate SQL</p> <pre><code> const std::string sql_insert = "INSERT INTO EventsLog " "(Sec, uSec, DeviceId, PmuId, EventId, Error, Msg) " "VALUES (%ld, %ld, %ld, %d, %ld, %d, %Q)"; const std::string sql_create = "CREATE TABLE IF NOT EXISTS EventsLog(" "Id INTEGER PRIMARY KEY AUTOINCREMENT, " "Sec INTEGER NOT NULL, " "uSec INTEGER NOT NULL, " "DeviceId INTEGER NOT NULL, " "PmuId INTEGER NOT NULL, " "EventId INTEGER NOT NULL, " "Error INTEGER NOT NULL, " "Msg TEXT" ")"; </code></pre> <p>In here, I generate the SQL INSERT command</p> <pre><code>std::string construct_sql_query (const ELMessageData &amp; data) { std::string query = ""; ptime jan1st1970 = ptime(date(1970,1,1)); ptime now = boost::posix_time::microsec_clock::universal_time(); time_duration delta = now - jan1st1970; TimeVal time((uint32)delta.total_seconds(), (uint32)now.time_of_day().fractional_seconds()); char * const sql = sqlite3_mprintf(sql_insert.c_str(), time.tv_sec, time.tv_usec, data.getDeviceId(), data.getPmuId(), data.getEventId(), (data.getIsError() ? 1 : 0), data.getExMsg().c_str()); if(sql == NULL) post_event(EvIOError("Failed to create the SQL command", "StLoggingEvents::_construct_sql_query")); query = std::string(sql); sqlite3_free(sql); return query; } // construct_sql_query </code></pre> <p>Here's the main loop in which I execute the INSERT commands</p> <pre><code> while(true) { m_exchange_obj-&gt;wait(); // wait for the semaphore to be raised const std::string sql = construct_sql_query (m_exchange_obj-&gt;receive()); char ** err = NULL; const int rc = sqlite3_exec(m_db_handle, sql.c_str(), NULL, NULL, err); sqlite3_free(err); if(rc != SQLITE_OK) { LERR_ &lt;&lt; "Error while inserting into the database"; LERR_ &lt;&lt; "Last SQL Query : "; LERR_ &lt;&lt; sql; } else { LDBG_ &lt;&lt; "Event logged..."; LDBG_ &lt;&lt; "Sqlite3 memory usage : " &lt;&lt; sqlite3_memory_used(); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload