/ Check-in [f09f11e9]
Login

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

Overview
Comment:Add experimental sqlite3_config option to control the native Win32 heap size.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | winHeapSize
Files: files | file ages | folders
SHA1: f09f11e94b5a7c2e51d99c3700d2acd2f3903de9
User & Date: mistachkin 2013-11-23 00:27:29
Context
2013-11-25
21:49
Clarify docs for the SQLITE_CONFIG_WIN32_HEAPSIZE option. Closed-Leaf check-in: 51e87607 user: mistachkin tags: winHeapSize
2013-11-23
00:27
Add experimental sqlite3_config option to control the native Win32 heap size. check-in: f09f11e9 user: mistachkin tags: winHeapSize
2013-11-22
21:32
Fix harmless compiler warning. check-in: f336c18f user: mistachkin tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Show Whitespace Changes Patch

Changes to src/main.c.

   510    510         }
   511    511         sqlite3GlobalConfig.mxMmap = mxMmap;
   512    512         if( szMmap<0 ) szMmap = SQLITE_DEFAULT_MMAP_SIZE;
   513    513         if( szMmap>mxMmap) szMmap = mxMmap;
   514    514         sqlite3GlobalConfig.szMmap = szMmap;
   515    515         break;
   516    516       }
          517  +
          518  +#if SQLITE_OS_WIN && defined(SQLITE_WIN32_MALLOC)
          519  +    case SQLITE_CONFIG_HEAP_SIZE: {
          520  +      sqlite3GlobalConfig.nHeap = va_arg(ap, int);
          521  +      break;
          522  +    }
          523  +#endif
   517    524   
   518    525       default: {
   519    526         rc = SQLITE_ERROR;
   520    527         break;
   521    528       }
   522    529     }
   523    530     va_end(ap);

Changes to src/os_win.c.

  1397   1397   
  1398   1398     if( !pWinMemData ) return SQLITE_ERROR;
  1399   1399     assert( pWinMemData->magic1==WINMEM_MAGIC1 );
  1400   1400     assert( pWinMemData->magic2==WINMEM_MAGIC2 );
  1401   1401   
  1402   1402   #if !SQLITE_OS_WINRT && SQLITE_WIN32_HEAP_CREATE
  1403   1403     if( !pWinMemData->hHeap ){
         1404  +    DWORD dwInitialSize = SQLITE_WIN32_HEAP_INIT_SIZE;
         1405  +    DWORD dwMaximumSize = (DWORD)sqlite3GlobalConfig.nHeap;
         1406  +    if( dwMaximumSize==0 ){
         1407  +      dwMaximumSize = SQLITE_WIN32_HEAP_MAX_SIZE;
         1408  +    }else if( dwInitialSize>dwMaximumSize ){
         1409  +      dwInitialSize = dwMaximumSize;
         1410  +    }
  1404   1411       pWinMemData->hHeap = osHeapCreate(SQLITE_WIN32_HEAP_FLAGS,
  1405         -                                      SQLITE_WIN32_HEAP_INIT_SIZE,
  1406         -                                      SQLITE_WIN32_HEAP_MAX_SIZE);
         1412  +                                      dwInitialSize, dwMaximumSize);
  1407   1413       if( !pWinMemData->hHeap ){
  1408   1414         sqlite3_log(SQLITE_NOMEM,
  1409         -          "failed to HeapCreate (%lu), flags=%u, initSize=%u, maxSize=%u",
  1410         -          osGetLastError(), SQLITE_WIN32_HEAP_FLAGS,
  1411         -          SQLITE_WIN32_HEAP_INIT_SIZE, SQLITE_WIN32_HEAP_MAX_SIZE);
         1415  +          "failed to HeapCreate (%lu), flags=%u, initSize=%lu, maxSize=%lu",
         1416  +          osGetLastError(), SQLITE_WIN32_HEAP_FLAGS, dwInitialSize,
         1417  +          dwMaximumSize);
  1412   1418         return SQLITE_NOMEM;
  1413   1419       }
  1414   1420       pWinMemData->bOwned = TRUE;
  1415   1421       assert( pWinMemData->bOwned );
  1416   1422     }
  1417   1423   #else
  1418   1424     pWinMemData->hHeap = osGetProcessHeap();

Changes to src/sqlite.h.in.

  1678   1678   ** either the [PRAGMA mmap_size] command, or by using the
  1679   1679   ** [SQLITE_FCNTL_MMAP_SIZE] file control.  ^(The maximum allowed mmap size
  1680   1680   ** cannot be changed at run-time.  Nor may the maximum allowed mmap size
  1681   1681   ** exceed the compile-time maximum mmap size set by the
  1682   1682   ** [SQLITE_MAX_MMAP_SIZE] compile-time option.)^
  1683   1683   ** ^If either argument to this option is negative, then that argument is
  1684   1684   ** changed to its compile-time default.
         1685  +**
         1686  +** [[SQLITE_CONFIG_HEAP_SIZE]]
         1687  +** <dt>SQLITE_CONFIG_HEAP_SIZE
         1688  +** <dd>^This option is only available if SQLite is compiled for Windows
         1689  +** with the [SQLITE_WIN32_MALLOC] pre-processor macro defined.
         1690  +** SQLITE_CONFIG_HEAP_SIZE takes a 32-bit integer value that specifies
         1691  +** the maximum size of the heap.
  1685   1692   ** </dl>
  1686   1693   */
  1687   1694   #define SQLITE_CONFIG_SINGLETHREAD  1  /* nil */
  1688   1695   #define SQLITE_CONFIG_MULTITHREAD   2  /* nil */
  1689   1696   #define SQLITE_CONFIG_SERIALIZED    3  /* nil */
  1690   1697   #define SQLITE_CONFIG_MALLOC        4  /* sqlite3_mem_methods* */
  1691   1698   #define SQLITE_CONFIG_GETMALLOC     5  /* sqlite3_mem_methods* */
................................................................................
  1702   1709   #define SQLITE_CONFIG_LOG          16  /* xFunc, void* */
  1703   1710   #define SQLITE_CONFIG_URI          17  /* int */
  1704   1711   #define SQLITE_CONFIG_PCACHE2      18  /* sqlite3_pcache_methods2* */
  1705   1712   #define SQLITE_CONFIG_GETPCACHE2   19  /* sqlite3_pcache_methods2* */
  1706   1713   #define SQLITE_CONFIG_COVERING_INDEX_SCAN 20  /* int */
  1707   1714   #define SQLITE_CONFIG_SQLLOG       21  /* xSqllog, void* */
  1708   1715   #define SQLITE_CONFIG_MMAP_SIZE    22  /* sqlite3_int64, sqlite3_int64 */
         1716  +#define SQLITE_CONFIG_HEAP_SIZE    23  /* int nByte */
  1709   1717   
  1710   1718   /*
  1711   1719   ** CAPI3REF: Database Connection Configuration Options
  1712   1720   **
  1713   1721   ** These constants are the available integer configuration options that
  1714   1722   ** can be passed as the second argument to the [sqlite3_db_config()] interface.
  1715   1723   **

Changes to src/test_config.c.

    58     58   #endif
    59     59   
    60     60   #if !SQLITE_OS_WINCE && !SQLITE_OS_WINRT
    61     61     Tcl_SetVar2(interp, "sqlite_options", "curdir", "1", TCL_GLOBAL_ONLY);
    62     62   #else
    63     63     Tcl_SetVar2(interp, "sqlite_options", "curdir", "0", TCL_GLOBAL_ONLY);
    64     64   #endif
           65  +
           66  +#ifdef SQLITE_WIN32_MALLOC
           67  +  Tcl_SetVar2(interp, "sqlite_options", "win32malloc", "1", TCL_GLOBAL_ONLY);
           68  +#else
           69  +  Tcl_SetVar2(interp, "sqlite_options", "win32malloc", "0", TCL_GLOBAL_ONLY);
           70  +#endif
    65     71   
    66     72   #ifdef SQLITE_DEBUG
    67     73     Tcl_SetVar2(interp, "sqlite_options", "debug", "1", TCL_GLOBAL_ONLY);
    68     74   #else
    69     75     Tcl_SetVar2(interp, "sqlite_options", "debug", "0", TCL_GLOBAL_ONLY);
    70     76   #endif
    71     77   

Changes to src/test_malloc.c.

  1125   1125       zBuf = realloc(zBuf, nByte);
  1126   1126       rc = sqlite3_config(SQLITE_CONFIG_HEAP, zBuf, nByte, nMinAlloc);
  1127   1127     }
  1128   1128   
  1129   1129     Tcl_SetResult(interp, (char *)sqlite3ErrName(rc), TCL_VOLATILE);
  1130   1130     return TCL_OK;
  1131   1131   }
         1132  +
         1133  +/*
         1134  +** Usage:    sqlite3_config_heap_size NBYTE
         1135  +*/
         1136  +static int test_config_heap_size(
         1137  +  void * clientData, 
         1138  +  Tcl_Interp *interp,
         1139  +  int objc,
         1140  +  Tcl_Obj *CONST objv[]
         1141  +){
         1142  +  int nByte;         /* Size to pass to sqlite3_config() */
         1143  +  int rc;            /* Return code of sqlite3_config() */
         1144  +
         1145  +  Tcl_Obj * CONST *aArg = &objv[1];
         1146  +  int nArg = objc-1;
         1147  +
         1148  +  if( nArg!=1 ){
         1149  +    Tcl_WrongNumArgs(interp, 1, objv, "NBYTE");
         1150  +    return TCL_ERROR;
         1151  +  }
         1152  +  if( Tcl_GetIntFromObj(interp, aArg[0], &nByte) ) return TCL_ERROR;
         1153  +
         1154  +  rc = sqlite3_config(SQLITE_CONFIG_HEAP_SIZE, nByte);
         1155  +
         1156  +  Tcl_SetResult(interp, (char *)sqlite3ErrName(rc), TCL_VOLATILE);
         1157  +  return TCL_OK;
         1158  +}
  1132   1159   
  1133   1160   /*
  1134   1161   ** Usage:    sqlite3_config_error  [DB]
  1135   1162   **
  1136   1163   ** Invoke sqlite3_config() or sqlite3_db_config() with invalid
  1137   1164   ** opcodes and verify that they return errors.
  1138   1165   */
................................................................................
  1469   1496        { "sqlite3_config_scratch",     test_config_scratch           ,0 },
  1470   1497        { "sqlite3_config_pagecache",   test_config_pagecache         ,0 },
  1471   1498        { "sqlite3_config_alt_pcache",  test_alt_pcache               ,0 },
  1472   1499        { "sqlite3_status",             test_status                   ,0 },
  1473   1500        { "sqlite3_db_status",          test_db_status                ,0 },
  1474   1501        { "install_malloc_faultsim",    test_install_malloc_faultsim  ,0 },
  1475   1502        { "sqlite3_config_heap",        test_config_heap              ,0 },
         1503  +     { "sqlite3_config_heap_size",   test_config_heap_size         ,0 },
  1476   1504        { "sqlite3_config_memstatus",   test_config_memstatus         ,0 },
  1477   1505        { "sqlite3_config_lookaside",   test_config_lookaside         ,0 },
  1478   1506        { "sqlite3_config_error",       test_config_error             ,0 },
  1479   1507        { "sqlite3_config_uri",         test_config_uri               ,0 },
  1480   1508        { "sqlite3_config_cis",         test_config_cis               ,0 },
  1481   1509        { "sqlite3_db_config_lookaside",test_db_config_lookaside      ,0 },
  1482   1510        { "sqlite3_dump_memsys3",       test_dump_memsys3             ,3 },

Added test/win32heap.test.

            1  +# 2013 November 22
            2  +#
            3  +# The author disclaims copyright to this source code.  In place of
            4  +# a legal notice, here is a blessing:
            5  +#
            6  +#    May you do good and not evil.
            7  +#    May you find forgiveness for yourself and forgive others.
            8  +#    May you share freely, never taking more than you give.
            9  +#
           10  +#***********************************************************************
           11  +# This file implements regression tests for SQLite library.  The
           12  +# focus of this script is recovery from transient manditory locks
           13  +# that sometimes appear on database files due to anti-virus software.
           14  +#
           15  +
           16  +if {$tcl_platform(platform)!="windows"} return
           17  +
           18  +set testdir [file dirname $argv0]
           19  +source $testdir/tester.tcl
           20  +
           21  +ifcapable !win32malloc {
           22  +  finish_test
           23  +  return
           24  +}
           25  +
           26  +set testprefix win32heap
           27  +
           28  +do_test 1.1 {
           29  +  catch {db close}
           30  +  sqlite3_shutdown
           31  +  sqlite3_config_heap_size 1048576
           32  +  sqlite3_initialize
           33  +} {SQLITE_OK}
           34  +
           35  +do_test 1.2 {
           36  +  sqlite3 db test.db
           37  +  catchsql {
           38  +    CREATE TABLE t1(x);
           39  +  }
           40  +} {0 {}}
           41  +
           42  +do_test 1.3 {
           43  +  catchsql {
           44  +    INSERT INTO t1 (x) VALUES(RANDOMBLOB(1048576));
           45  +  }
           46  +} {1 {out of memory}}
           47  +
           48  +do_test 1.4 {
           49  +  catchsql {
           50  +    SELECT COUNT(*) FROM t1;
           51  +  }
           52  +} {0 0}
           53  +
           54  +do_test 1.5 {
           55  +  catch {db close}
           56  +  sqlite3_shutdown
           57  +  sqlite3_config_heap_size 0
           58  +  sqlite3_initialize
           59  +} {SQLITE_OK}
           60  +
           61  +do_test 1.6 {
           62  +  sqlite3 db test.db
           63  +  catchsql {
           64  +    INSERT INTO t1 (x) VALUES(RANDOMBLOB(1048576));
           65  +  }
           66  +} {0 {}}
           67  +
           68  +do_test 1.7 {
           69  +  catchsql {
           70  +    SELECT COUNT(*) FROM t1;
           71  +  }
           72  +} {0 1}
           73  +
           74  +finish_test