title: RAM consumption inside a C++ program using Sqlite3 blob
body: <p>I'm using sqlite3 dbms inside a C++ program that I use mainly to store files as blob objects (I know that's not the best option).</p>
  
  <p>Obviously I write them incrementally since they can be sometimes large (40-80MB) in order to do so I have to create first a placeholder of the blob using the binding function <code>sqlite3_bind_zeroblob(...)</code> and after that I open the blob writing and reading incrementally from and to it.</p>
  
  <p>The problem I'm facing is that when i create the blob placeholder (during <code>sqlite3_step</code>) the RAM consumption of my app reaches 80-160MB for 2-3 seconds, once it has been created the RAM consumption goes back to 2-3MB at most.</p>
  
  <p>I do not get why! If they created a way to write to a blob incrementally there is for sure a way to create that stupid placeholder without wasting 160MB of RAM, but I didn't find it. Have you got any suggestion?</p>
  
  <pre><code>sqlite3_stmt* stm = NULL;
  sqlite3_blob *BLOB = NULL;
  
  rc = sqlite3_prepare_v2(db, sql.c_str(), -1, &amp;stm, NULL);
  
  rc = sqlite3_bind_blob(stm, 1, wpath.c_str(), wpath.size()*sizeof(wchar_t), SQLITE_STATIC);
  rc = sqlite3_bind_text(stm, 2, hash.c_str(), hash.size(), SQLITE_STATIC);
  rc = sqlite3_bind_zeroblob(stm, 3, size);
  rc = sqlite3_bind_int(stm, 4, versione);
  rc = sqlite3_bind_blob(stm, 5, last.c_str(), last.size()*sizeof(wchar_t), SQLITE_STATIC);
  
  rc = sqlite3_step(stm);
  
  if (rc != SQLITE_DONE) {
      fprintf(stderr, " This file was already present in the database!\n", rc);
      return;
  }
  else {
      fprintf(stdout, "Record FILE created successfully\n");
  }
  </code></pre>