/ Check-in [3e852804]
Login
SQLite training in Houston TX on 2019-11-05 (details)
Part of the 2019 Tcl Conference

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

Overview
Comment:Remember the size of the Vdbe.aOp[] array in bytes, to avoid unnecessary calls to sqlite3_msize().
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 3e852804c85a5c9f4c4ffafd55d03af6d19fe5cc
User & Date: drh 2016-01-01 16:42:09
Context
2016-01-02
05:00
Fix a (harmless) typo in an #ifdef for SQLITE_ENABLE_CURSOR_HINTS check-in: 2047d2de user: drh tags: trunk
2016-01-01
16:42
Remember the size of the Vdbe.aOp[] array in bytes, to avoid unnecessary calls to sqlite3_msize(). check-in: 3e852804 user: drh tags: trunk
16:26
Avoid misaligned memory allocations on Sparc in sqlite3VdbeMakeReady(). This fixes a problem introduced by check-in [a9e819082b]. check-in: a304e346 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/sqliteInt.h.

  2728   2728     int iRangeReg;       /* First register in temporary register block */
  2729   2729     int nErr;            /* Number of errors seen */
  2730   2730     int nTab;            /* Number of previously allocated VDBE cursors */
  2731   2731     int nMem;            /* Number of memory cells used so far */
  2732   2732     int nSet;            /* Number of sets used so far */
  2733   2733     int nOnce;           /* Number of OP_Once instructions so far */
  2734   2734     int nOpAlloc;        /* Number of slots allocated for Vdbe.aOp[] */
         2735  +  int szOpAlloc;       /* Bytes of memory space allocated for Vdbe.aOp[] */
  2735   2736     int iFixedOp;        /* Never back out opcodes iFixedOp-1 or earlier */
  2736   2737     int ckBase;          /* Base register of data during check constraints */
  2737   2738     int iSelfTab;        /* Table of an index whose exprs are being coded */
  2738   2739     int iCacheLevel;     /* ColCache valid when aColCache[].iLevel<=iCacheLevel */
  2739   2740     int iCacheCnt;       /* Counter used to generate aColCache[].lru values */
  2740   2741     int nLabel;          /* Number of labels used */
  2741   2742     int *aLabel;         /* Space to hold the labels */

Changes to src/vdbeaux.c.

    31     31     p->pPrev = 0;
    32     32     db->pVdbe = p;
    33     33     p->magic = VDBE_MAGIC_INIT;
    34     34     p->pParse = pParse;
    35     35     assert( pParse->aLabel==0 );
    36     36     assert( pParse->nLabel==0 );
    37     37     assert( pParse->nOpAlloc==0 );
           38  +  assert( pParse->szOpAlloc==0 );
    38     39     return p;
    39     40   }
    40     41   
    41     42   /*
    42     43   ** Change the error string stored in Vdbe.zErrMsg
    43     44   */
    44     45   void sqlite3VdbeError(Vdbe *p, const char *zFormat, ...){
................................................................................
   120    121     UNUSED_PARAMETER(nOp);
   121    122   #endif
   122    123   
   123    124     assert( nOp<=(1024/sizeof(Op)) );
   124    125     assert( nNew>=(p->nOpAlloc+nOp) );
   125    126     pNew = sqlite3DbRealloc(p->db, v->aOp, nNew*sizeof(Op));
   126    127     if( pNew ){
   127         -    p->nOpAlloc = sqlite3DbMallocSize(p->db, pNew)/sizeof(Op);
          128  +    p->szOpAlloc = sqlite3DbMallocSize(p->db, pNew);
          129  +    p->nOpAlloc = p->szOpAlloc/sizeof(Op);
   128    130       v->aOp = pNew;
   129    131     }
   130    132     return (pNew ? SQLITE_OK : SQLITE_NOMEM);
   131    133   }
   132    134   
   133    135   #ifdef SQLITE_DEBUG
   134    136   /* This routine is just a convenient place to set a breakpoint that will
................................................................................
  1845   1847     ** See also: allocateCursor().
  1846   1848     */
  1847   1849     nMem += nCursor;
  1848   1850   
  1849   1851     /* Allocate space for memory registers, SQL variables, VDBE cursors and 
  1850   1852     ** an array to marshal SQL function arguments in.
  1851   1853     */
  1852         -  zCsr = ((u8*)p->aOp) + ROUND8(sizeof(Op)*p->nOp);       /* Available space */
  1853         -  nFree = sqlite3_msize(p->aOp) - ROUND8(sizeof(Op)*p->nOp); /* Size of zCsr */
         1854  +  zCsr = ((u8*)p->aOp) + ROUND8(sizeof(Op)*p->nOp);      /* Available space */
         1855  +  nFree = pParse->szOpAlloc - ROUND8(sizeof(Op)*p->nOp); /* Size of zCsr */
  1854   1856   
  1855   1857     resolveP2Values(p, &nArg);
  1856   1858     p->usesStmtJournal = (u8)(pParse->isMultiWrite && pParse->mayAbort);
  1857   1859     if( pParse->explain && nMem<10 ){
  1858   1860       nMem = 10;
  1859   1861     }
  1860   1862     memset(zCsr, 0, nFree);