1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-11-06 15:49:35 +03:00

Added new configuration options to query the low-level malloc interface

and to provide memory buffers for scratch, page-cache, and heap memory
allocators. (CVS 5231)

FossilOrigin-Name: e36201a352f832c97c5c0fcb872c1f094cac03d2
This commit is contained in:
drh
2008-06-18 13:27:46 +00:00
parent 1a9ed0b27a
commit 335897970c
5 changed files with 119 additions and 22 deletions

View File

@@ -1,5 +1,5 @@
C Add\ssome\stest\sinfrastructure\sand\scases\sfor\sthe\snew\smutex\sapi.\s(CVS\s5230)
D 2008-06-18T09:45:56
C Added\snew\sconfiguration\soptions\sto\squery\sthe\slow-level\smalloc\sinterface\nand\sto\sprovide\smemory\sbuffers\sfor\sscratch,\spage-cache,\sand\sheap\smemory\nallocators.\s(CVS\s5231)
D 2008-06-18T13:27:47
F Makefile.arm-wince-mingw32ce-gcc ac5f7b2cef0cd850d6f755ba6ee4ab961b1fadf7
F Makefile.in dc5608df93faf4406cfd7a1c8ed9ab93d8bfbfd5
F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
@@ -115,7 +115,7 @@ F src/insert.c c2ead6c36566de8e3f130e7ab1431723a269d5d7
F src/journal.c cffd2cd214e58c0e99c3ff632b3bee6c7cbb260e
F src/legacy.c 3626c71fb70912abec9a4312beba753a9ce800df
F src/loadext.c f99a75534a53e281fa2461239ee4a4b4bf6ad564
F src/main.c 21807e7bff6176030ac14ebf49c8a85479349689
F src/main.c 34c9d9f99e0c6df25ac9d6e1a9c0964d8170cbe2
F src/malloc.c 7b622d22f29e3be56d271a5a921f3b5788330189
F src/md5.c 008216bbb5d34c6fbab5357aa68575ad8a31516a
F src/mem1.c 159f10e280f2d9aea597cf938851e61652dd5c3d
@@ -143,9 +143,9 @@ F src/printf.c 8b063da9dcde26b7c500a01444b718d86f21bc6e
F src/random.c 2b2db2de4ab491f5a14d3480466f8f4b5a5db74a
F src/select.c 669687459e7d0193c89de06c5dbed55b4a41191c
F src/shell.c a12ea645271b7876c8f080146f48e20b00d367ec
F src/sqlite.h.in 4724c4c3fb66c0e696edd6aec3b3d79c33c09d0a
F src/sqlite.h.in ada07a820e5a9d1264e2f9736f2bf7edd0a623ff
F src/sqlite3ext.h faacd0e6a81aabee0861c6d7883c9172e74ef5b3
F src/sqliteInt.h f465a6d45e9cabadad5c6c097d17df3c054616d0
F src/sqliteInt.h 90dff45c2fa188ff8763dd5358f7b1040e1bb4fb
F src/sqliteLimit.h f435e728c6b620ef7312814d660a81f9356eb5c8
F src/table.c 1fa8f8113ac9cbc09ae4801c6d2a7f0af82c5822
F src/tclsqlite.c 4dd9ee4cb44846ad9bcc4d0da8088c1e7d4b33d9
@@ -596,7 +596,7 @@ F tool/speedtest16.c c8a9c793df96db7e4933f0852abb7a03d48f2e81
F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
F tool/speedtest8.c 1dbced29de5f59ba2ebf877edcadf171540374d1
F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
P 39b4e1ff4e3db3278c35eff10bbabdf4d87793a4
R a0d49cf1341289981a00a4ad9da3e9bc
U danielk1977
Z 963819c2af16f4cb39a0c216ae54cc59
P 262baee9952b28afe5dc77eb7365ebb11a480906
R 5f557fa3b0a0319b470b2906d72f8bb7
U drh
Z 9163b748554dc08433fe2724996f3f54

View File

@@ -1 +1 @@
262baee9952b28afe5dc77eb7365ebb11a480906
e36201a352f832c97c5c0fcb872c1f094cac03d2

View File

@@ -14,7 +14,7 @@
** 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 <ctype.h>
@@ -151,6 +151,12 @@ int sqlite3_config(int op, ...){
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*);
@@ -166,6 +172,27 @@ int sqlite3_config(int op, ...){
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;

View File

@@ -30,7 +30,7 @@
** 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_
@@ -1032,6 +1032,14 @@ struct sqlite3_mem_methods {
** alternative low-level memory allocation routines to be used in place
** the memory allocation routines built into SQLite.</dd>
**
** <dt>SQLITE_CONFIG_GETMALLOC</dt>
** <dd>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.</dd>
**
** <dt>SQLITE_CONFIG_MEMSTATUS</dt>
** <dd>This option takes single boolean argument which enables or disables
** the collection of memory allocation statistics. When disabled, the
@@ -1043,18 +1051,73 @@ struct sqlite3_mem_methods {
** <li> sqlite3_memory_status()
** </ul>
** </dd>
**
** <dt>SQLITE_CONFIG_SCRATCH</dt>
** <dd>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.
** </dd>
**
** <dt>SQLITE_CONFIG_PAGECACHE</dt>
** <dd>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.
** </dd>
**
** <dt>SQLITE_CONFIG_HEAP</dt>
** <dd>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.
** </dd>
**
** <dt>SQLITE_CONFIG_MUTEX</dt>
** <dd>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.</dd>
**
** <dt>SQLITE_CONFIG_GETMALLOC</dt>
** <dd>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.</dd>
**
** </dl>
*/
#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* */
/*

View File

@@ -11,7 +11,7 @@
*************************************************************************
** 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_
@@ -1733,6 +1733,8 @@ typedef struct {
/*
** 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 */
@@ -1741,9 +1743,14 @@ struct Sqlite3Config {
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[] */
};
/*