Index: src/main.c ================================================================== --- src/main.c +++ src/main.c @@ -12,11 +12,11 @@ ** Main file for the SQLite library. The routines in this file ** implement the programmer interface to the library. Routines in ** other files are for internal use by SQLite and should not be ** accessed by users of the library. ** -** $Id: main.c,v 1.447 2008/06/18 09:45:56 danielk1977 Exp $ +** $Id: main.c,v 1.448 2008/06/18 13:27:47 drh Exp $ */ #include "sqliteInt.h" #include #ifdef SQLITE_ENABLE_FTS3 @@ -148,10 +148,16 @@ } case SQLITE_CONFIG_MALLOC: { /* Specify an alternative malloc implementation */ sqlite3Config.m = *va_arg(ap, sqlite3_mem_methods*); break; + } + case SQLITE_CONFIG_GETMALLOC: { + /* Specify an alternative malloc implementation */ + if( sqlite3Config.m.xMalloc==0 ) sqlite3MemSetDefault(); + *va_arg(ap, sqlite3_mem_methods*) = sqlite3Config.m; + break; } case SQLITE_CONFIG_MUTEX: { /* Specify an alternative mutex implementation */ sqlite3Config.mutex = *va_arg(ap, sqlite3_mutex_methods*); break; @@ -163,10 +169,31 @@ } case SQLITE_CONFIG_MEMSTATUS: { /* Enable or disable the malloc status collection */ sqlite3Config.bMemstat = va_arg(ap, int); break; + } + case SQLITE_CONFIG_SCRATCH: { + /* Designate a buffer for scratch memory space */ + sqlite3Config.pScratch = va_arg(ap, void*); + sqlite3Config.szScratch = va_arg(ap, int); + sqlite3Config.nScratch = va_arg(ap, int); + break; + } + case SQLITE_CONFIG_PAGECACHE: { + /* Designate a buffer for scratch memory space */ + sqlite3Config.pPage = va_arg(ap, void*); + sqlite3Config.szPage = va_arg(ap, int); + sqlite3Config.nPage = va_arg(ap, int); + break; + } + case SQLITE_CONFIG_HEAP: { + /* Designate a buffer for scratch memory space */ + sqlite3Config.pHeap = va_arg(ap, void*); + sqlite3Config.nHeap = va_arg(ap, int); + sqlite3Config.mnReq = va_arg(ap, int); + break; } default: { rc = SQLITE_ERROR; break; } Index: src/sqlite.h.in ================================================================== --- src/sqlite.h.in +++ src/sqlite.h.in @@ -28,11 +28,11 @@ ** The name of this file under configuration management is "sqlite.h.in". ** The makefile makes some minor changes to this file (such as inserting ** the version number) and changes its name to "sqlite3.h" as ** part of the build process. ** -** @(#) $Id: sqlite.h.in,v 1.332 2008/06/18 09:45:56 danielk1977 Exp $ +** @(#) $Id: sqlite.h.in,v 1.333 2008/06/18 13:27:47 drh Exp $ */ #ifndef _SQLITE3_H_ #define _SQLITE3_H_ #include /* Needed for the definition of va_list */ @@ -1030,10 +1030,18 @@ **
This option takes a single argument which is a pointer to an ** instance of the [sqlite3_mem_methods] structure. The argument specifics ** alternative low-level memory allocation routines to be used in place ** the memory allocation routines built into SQLite.
** +**
SQLITE_CONFIG_GETMALLOC
+**
This option takes a single argument which is a pointer to an +** instance of the [sqlite3_mem_methods] structure. The [sqlite3_mem_methods] +** structure is filled with the currently defined memory allocation routines. +** This option can be used to overload the default memory allocation +** routines with a wrapper that simulations memory allocation failure or +** tracks memory usage, for example.
+** **
SQLITE_CONFIG_MEMSTATUS
**
This option takes single boolean argument which enables or disables ** the collection of memory allocation statistics. When disabled, the ** following SQLite interfaces become non-operational: **
    @@ -1041,22 +1049,77 @@ **
  • [sqlite3_memory_highwater()] **
  • [sqlite3_soft_heap_limit()] **
  • sqlite3_memory_status() **
**
+** +**
SQLITE_CONFIG_SCRATCH
+**
This option specifies a static memory buffer that SQLite can use for +** scratch memory. There are three arguments: A pointer to the memory, the +** size of each scratch buffer (sz), and the number of buffers (N). The first +** argument should point to an allocation of at least sz*N bytes of memory. +** SQLite will use no more than one scratch buffer at once per thread, so +** N should be set to the expected maximum number of threads. The sz +** parameter should be 6 times the size of the largest database page size. +** Scratch buffers are used as part of the btree balance operation. If +** The btree balancer needs additional memory beyond what is provided by +** scratch buffers or if no scratch buffer space is specified, then SQLite +** goes to [sqlite3_malloc()] to obtain the memory it needs. +**
+** +**
SQLITE_CONFIG_PAGECACHE
+**
This option specifies a static memory buffer that SQLite can use for +** the database page cache. There are three arguments: +** A pointer to the memory, the +** size of each page buffer (sz), and the number of pages (N). The first +** argument should point to an allocation of at least sz*N bytes of memory. +** SQLite will use the memory provided by the first argument to satisfy +** its memory needs for the first N pages that it adds to cache. If +** additional page cache memory is needed beyond what is provided by +** this option, then SQLite goes to [sqlite3_malloc()] for the additional +** storage space. +**
+** +**
SQLITE_CONFIG_HEAP
+**
This option specifies a static memory buffer that SQLite will use +** for all of its dynamic memory allocation needs beyond those provided +** for by [SQLITE_CONFIG_SCRATCH] and [SQLITE_CONFIG_PAGECACHE]. +** There are three arguments: A pointer to the memory, the number of +** bytes in the memory buffer, and the minimum allocation size. When +** this configuration option is used, SQLite never calls the system +** malloc() implementation but instead uses the supplied memory buffer +** to satisfy all [sqlite3_malloc()] requests. +**
+** +**
SQLITE_CONFIG_MUTEX
+**
This option takes a single argument which is a pointer to an +** instance of the [sqlite3_mutex_methods] structure. The argument specifics +** alternative low-level mutex routines to be used in place +** the mutex routines built into SQLite.
+** +**
SQLITE_CONFIG_GETMALLOC
+**
This option takes a single argument which is a pointer to an +** instance of the [sqlite3_mutex_methods] structure. The +** [sqlite3_mutex_methods] +** structure is filled with the currently defined mutex routines. +** This option can be used to overload the default mutex allocation +** routines with a wrapper used to track mutex usage for performance +** profiling or testing, for example.
+** ** */ #define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */ #define SQLITE_CONFIG_MULTITHREAD 2 /* nil */ #define SQLITE_CONFIG_SERIALIZED 3 /* nil */ #define SQLITE_CONFIG_MALLOC 4 /* sqlite3_mem_methods* */ -#define SQLITE_CONFIG_MEMSTATUS 5 /* boolean */ -#define SQLITE_CONFIG_MUTEX 6 /* sqlite3_mutex_methods* */ -#define SQLITE_CONFIG_GETMUTEX 7 /* sqlite3_mutex_methods* */ - -/* These options are to be added later. Currently unused and undocumented. */ -#define SQLITE_CONFIG_HEAP 8 /* void*, int64, min, max, tmp */ +#define SQLITE_CONFIG_GETMALLOC 5 /* sqlite3_mem_methods* */ +#define SQLITE_CONFIG_SCRATCH 6 /* void*, int sz, int N */ +#define SQLITE_CONFIG_PAGECACHE 7 /* void*, int sz, int N */ +#define SQLITE_CONFIG_HEAP 8 /* void*, int nByte, int min */ +#define SQLITE_CONFIG_MEMSTATUS 9 /* boolean */ +#define SQLITE_CONFIG_MUTEX 10 /* sqlite3_mutex_methods* */ +#define SQLITE_CONFIG_GETMUTEX 11 /* sqlite3_mutex_methods* */ /* ** CAPI3REF: Enable Or Disable Extended Result Codes {F12200} ** Index: src/sqliteInt.h ================================================================== --- src/sqliteInt.h +++ src/sqliteInt.h @@ -9,11 +9,11 @@ ** May you share freely, never taking more than you give. ** ************************************************************************* ** Internal interface definitions for SQLite. ** -** @(#) $Id: sqliteInt.h,v 1.712 2008/06/17 17:21:18 danielk1977 Exp $ +** @(#) $Id: sqliteInt.h,v 1.713 2008/06/18 13:27:47 drh Exp $ */ #ifndef _SQLITEINT_H_ #define _SQLITEINT_H_ /* @@ -1731,21 +1731,28 @@ int rc; /* Result code stored here */ } InitData; /* ** Structure containing global configuration data for the SQLite library. +** +** This structure also contains some state information. */ struct Sqlite3Config { int bMemstat; /* True to enable memory status */ int bCoreMutex; /* True to enable core mutexing */ int bFullMutex; /* True to enable full mutexing */ sqlite3_mem_methods m; /* Low-level memory allocation interface */ sqlite3_mutex_methods mutex; /* Low-level mutex interface */ void *pHeap; /* Heap storage space */ - sqlite3_int64 nHeap; /* Size of pHeap[] */ - int mnReq, mxReq; /* Min and max memory request sizes */ - int nTemp; /* Part of pHeap for temporary allos */ + int nHeap; /* Size of pHeap[] */ + int mnReq, mxReq; /* Min and max heap requests sizes */ + void *pScratch; /* Scratch memory */ + int szScratch; /* Size of each scratch buffer */ + int nScratch; /* Number of scratch buffers */ + void *pPage; /* Page cache memory */ + int szPage; /* Size of each page in pPage[] */ + int nPage; /* Number of pages in pPage[] */ }; /* ** Assuming zIn points to the first byte of a UTF-8 character, ** advance zIn to point to the first byte of the next UTF-8 character.