/ Check-in [6da6f46d]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Another memory allocator performance optimization.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 6da6f46d0c43e3b68c21f514ddf8ee663c20f249
User & Date: drh 2014-08-23 19:42:06
Context
2014-08-23
20:25
Faster implementation of the sqlite3ApiExit() routine. check-in: bd41d394 user: drh tags: trunk
19:42
Another memory allocator performance optimization. check-in: 6da6f46d user: drh tags: trunk
19:08
Fix a variable-declaration after code problem in btree.c. Harmless in GCC and CLANG but unacceptable for MSVC. check-in: 45abd5c0 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/malloc.c.

   472    472       sqlite3StatusAdd(SQLITE_STATUS_MALLOC_COUNT, -1);
   473    473       sqlite3GlobalConfig.m.xFree(p);
   474    474       sqlite3_mutex_leave(mem0.mutex);
   475    475     }else{
   476    476       sqlite3GlobalConfig.m.xFree(p);
   477    477     }
   478    478   }
          479  +
          480  +/*
          481  +** Add the size of memory allocation "p" to the count in
          482  +** *db->pnBytesFreed.
          483  +*/
          484  +static SQLITE_NOINLINE void measureAllocationSize(sqlite3 *db, void *p){
          485  +  *db->pnBytesFreed += sqlite3DbMallocSize(db,p);
          486  +}
   479    487   
   480    488   /*
   481    489   ** Free memory that might be associated with a particular database
   482    490   ** connection.
   483    491   */
   484    492   void sqlite3DbFree(sqlite3 *db, void *p){
   485    493     assert( db==0 || sqlite3_mutex_held(db->mutex) );
   486    494     if( p==0 ) return;
   487    495     if( db ){
   488    496       if( db->pnBytesFreed ){
   489         -      *db->pnBytesFreed += sqlite3DbMallocSize(db, p);
          497  +      measureAllocationSize(db, p);
   490    498         return;
   491    499       }
   492    500       if( isLookaside(db, p) ){
   493    501         LookasideSlot *pBuf = (LookasideSlot*)p;
   494    502   #if SQLITE_DEBUG
   495    503         /* Trash all content in the buffer being freed */
   496    504         memset(p, 0xaa, db->lookaside.sz);