aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/btree.c21
-rw-r--r--src/malloc.c40
-rw-r--r--src/mem1.c4
-rw-r--r--src/mem2.c4
-rw-r--r--src/pager.c53
-rw-r--r--src/sqlite.h.in14
-rw-r--r--src/sqliteInt.h8
7 files changed, 72 insertions, 72 deletions
diff --git a/src/btree.c b/src/btree.c
index 1140e7756..be003249c 100644
--- a/src/btree.c
+++ b/src/btree.c
@@ -9,7 +9,7 @@
** May you share freely, never taking more than you give.
**
*************************************************************************
-** $Id: btree.c,v 1.464 2008/06/15 02:51:47 drh Exp $
+** $Id: btree.c,v 1.465 2008/06/17 15:12:01 drh Exp $
**
** This file implements a external (disk-based) database using BTrees.
** See the header comment on "btreeInt.h" for additional information.
@@ -3719,14 +3719,14 @@ int sqlite3BtreeMoveto(
if( available>=nCellKey ){
c = sqlite3VdbeRecordCompare(nCellKey, pCellKey, pUnKey);
}else{
- pCellKey = sqlite3TempMalloc( nCellKey );
+ pCellKey = sqlite3Malloc( nCellKey );
if( pCellKey==0 ){
rc = SQLITE_NOMEM;
goto moveto_finish;
}
rc = sqlite3BtreeKey(pCur, 0, nCellKey, (void *)pCellKey);
c = sqlite3VdbeRecordCompare(nCellKey, pCellKey, pUnKey);
- sqlite3TempFree(pCellKey);
+ sqlite3_free(pCellKey);
if( rc ) goto moveto_finish;
}
}
@@ -4860,6 +4860,7 @@ static int balance_nonroot(MemPage *pPage){
int subtotal; /* Subtotal of bytes in cells on one page */
int iSpace1 = 0; /* First unused byte of aSpace1[] */
int iSpace2 = 0; /* First unused byte of aSpace2[] */
+ int szScratch; /* Size of scratch memory requested */
MemPage *apOld[NB]; /* pPage and up to two siblings */
Pgno pgnoOld[NB]; /* Page numbers for each page in apOld[] */
MemPage *apCopy[NB]; /* Private copies of apOld[] pages */
@@ -4990,13 +4991,13 @@ static int balance_nonroot(MemPage *pPage){
/*
** Allocate space for memory structures
*/
- apCell = sqlite3TempMalloc(
+ szScratch =
nMaxCells*sizeof(u8*) /* apCell */
+ nMaxCells*sizeof(u16) /* szCell */
+ (ROUND8(sizeof(MemPage))+pBt->pageSize)*NB /* aCopy */
+ pBt->pageSize /* aSpace1 */
- + (ISAUTOVACUUM ? nMaxCells : 0) /* aFrom */
- );
+ + (ISAUTOVACUUM ? nMaxCells : 0); /* aFrom */
+ apCell = sqlite3ScratchMalloc( szScratch );
if( apCell==0 ){
rc = SQLITE_NOMEM;
goto balance_cleanup;
@@ -5015,7 +5016,7 @@ static int balance_nonroot(MemPage *pPage){
aFrom = &aSpace1[pBt->pageSize];
}
#endif
- aSpace2 = sqlite3Malloc(pBt->pageSize);
+ aSpace2 = sqlite3PageMalloc(pBt->pageSize);
if( aSpace2==0 ){
rc = SQLITE_NOMEM;
goto balance_cleanup;
@@ -5397,7 +5398,7 @@ static int balance_nonroot(MemPage *pPage){
** But the parent page will always be initialized.
*/
assert( pParent->isInit );
- sqlite3TempFree(apCell);
+ sqlite3ScratchFree(apCell);
apCell = 0;
rc = balance(pParent, 0);
@@ -5405,8 +5406,8 @@ static int balance_nonroot(MemPage *pPage){
** Cleanup before returning.
*/
balance_cleanup:
- sqlite3_free(aSpace2);
- sqlite3TempFree(apCell);
+ sqlite3PageFree(aSpace2);
+ sqlite3ScratchFree(apCell);
for(i=0; i<nOld; i++){
releasePage(apOld[i]);
}
diff --git a/src/malloc.c b/src/malloc.c
index 3c567c9c0..7db0eacc3 100644
--- a/src/malloc.c
+++ b/src/malloc.c
@@ -12,7 +12,7 @@
**
** Memory allocation functions used throughout sqlite.
**
-** $Id: malloc.c,v 1.17 2008/06/15 02:51:48 drh Exp $
+** $Id: malloc.c,v 1.18 2008/06/17 15:12:01 drh Exp $
*/
#include "sqliteInt.h"
#include <stdarg.h>
@@ -91,7 +91,7 @@ static struct {
sqlite3_int64 nowUsed; /* Main memory currently in use */
sqlite3_int64 mxUsed; /* Highwater mark for nowUsed */
int mxReq; /* Max request size for ordinary mallocs */
- int mxTempReq; /* Max request size for xTemp mallocs */
+ int mxScratchReq; /* Max request size for xTemp mallocs */
} mem0;
/*
@@ -229,12 +229,12 @@ void *sqlite3_malloc(int n){
/*
** Each thread may only have a single outstanding allocation from
-** xTempMalloc(). We verify this constraint in the single-threaded
-** case by setting tempAllocOut to 1 when an allocation
+** xScratchMalloc(). We verify this constraint in the single-threaded
+** case by setting scratchAllocOut to 1 when an allocation
** is outstanding clearing it when the allocation is freed.
*/
#if SQLITE_THREADSAFE==0 && !defined(NDEBUG)
-static int tempAllocOut = 0;
+static int scratchAllocOut = 0;
#endif
@@ -246,37 +246,47 @@ static int tempAllocOut = 0;
** structures that would not normally fit on the stack of an
** embedded processor.
*/
-void *sqlite3TempMalloc(int n){
+void *sqlite3ScratchMalloc(int n){
void *p;
assert( n>0 );
if( sqlite3FaultStep(SQLITE_FAULTINJECTOR_MALLOC) ){
return 0;
}
#if SQLITE_THREADSAFE==0 && !defined(NDEBUG)
- assert( tempAllocOut==0 );
- tempAllocOut = 1;
+ assert( scratchAllocOut==0 );
+ scratchAllocOut = 1;
#endif
if( sqlite3Config.bMemstat ){
sqlite3_mutex_enter(mem0.mutex);
- if( n>mem0.mxTempReq ) mem0.mxTempReq = n;
- p = sqlite3Config.m.xTempMalloc(n);
+ if( n>mem0.mxScratchReq ) mem0.mxScratchReq = n;
+ p = sqlite3Config.m.xMalloc(n);
sqlite3_mutex_leave(mem0.mutex);
}else{
- p = sqlite3Config.m.xTempMalloc(n);
+ p = sqlite3Config.m.xMalloc(n);
}
return p;
}
-void sqlite3TempFree(void *p){
+void sqlite3ScratchFree(void *p){
if( p ){
#if SQLITE_THREADSAFE==0 && !defined(NDEBUG)
- assert( tempAllocOut==1 );
- tempAllocOut = 0;
+ assert( scratchAllocOut==1 );
+ scratchAllocOut = 0;
#endif
- sqlite3Config.m.xTempFree(p);
+ sqlite3Config.m.xFree(p);
}
}
/*
+** Place holders for the page-cache memory allocator.
+*/
+void *sqlite3PageMalloc(int iSize){
+ return sqlite3Malloc(iSize);
+}
+void sqlite3PageFree(void *pOld){
+ sqlite3_free(pOld);
+}
+
+/*
** Return the size of a memory allocation previously obtained from
** sqlite3Malloc() or sqlite3_malloc().
*/
diff --git a/src/mem1.c b/src/mem1.c
index 120fc040c..e42322538 100644
--- a/src/mem1.c
+++ b/src/mem1.c
@@ -17,7 +17,7 @@
** This file contains implementations of the low-level memory allocation
** routines specified in the sqlite3_mem_methods object.
**
-** $Id: mem1.c,v 1.20 2008/06/15 02:51:48 drh Exp $
+** $Id: mem1.c,v 1.21 2008/06/17 15:12:01 drh Exp $
*/
#include "sqliteInt.h"
@@ -130,8 +130,6 @@ void sqlite3MemSetDefault(void){
sqlite3MemRealloc,
sqlite3MemSize,
sqlite3MemRoundup,
- sqlite3MemMalloc,
- sqlite3MemFree,
sqlite3MemInit,
sqlite3MemShutdown,
0
diff --git a/src/mem2.c b/src/mem2.c
index ffc31987c..311f02dbd 100644
--- a/src/mem2.c
+++ b/src/mem2.c
@@ -19,7 +19,7 @@
** This file contains implementations of the low-level memory allocation
** routines specified in the sqlite3_mem_methods object.
**
-** $Id: mem2.c,v 1.29 2008/06/15 02:51:48 drh Exp $
+** $Id: mem2.c,v 1.30 2008/06/17 15:12:01 drh Exp $
*/
#include "sqliteInt.h"
@@ -312,8 +312,6 @@ void sqlite3MemSetDefault(void){
sqlite3MemRealloc,
sqlite3MemSize,
sqlite3MemRoundup,
- sqlite3MemMalloc,
- sqlite3MemFree,
sqlite3MemInit,
sqlite3MemShutdown,
0
diff --git a/src/pager.c b/src/pager.c
index 5dab5a41d..b1e08e848 100644
--- a/src/pager.c
+++ b/src/pager.c
@@ -18,7 +18,7 @@
** file simultaneously, or one process from reading the database while
** another is writing.
**
-** @(#) $Id: pager.c,v 1.457 2008/06/15 02:51:48 drh Exp $
+** @(#) $Id: pager.c,v 1.458 2008/06/17 15:12:01 drh Exp $
*/
#ifndef SQLITE_OMIT_DISKIO
#include "sqliteInt.h"
@@ -773,19 +773,20 @@ static int osUnlock(sqlite3_file *pFd, int eLock){
static int jrnlBufferSize(Pager *pPager){
int dc; /* Device characteristics */
int nSector; /* Sector size */
- int nPage; /* Page size */
+ int szPage; /* Page size */
sqlite3_file *fd = pPager->fd;
if( fd->pMethods ){
dc = sqlite3OsDeviceCharacteristics(fd);
nSector = sqlite3OsSectorSize(fd);
- nPage = pPager->pageSize;
+ szPage = pPager->pageSize;
}
assert(SQLITE_IOCAP_ATOMIC512==(512>>8));
assert(SQLITE_IOCAP_ATOMIC64K==(65536>>8));
- if( !fd->pMethods || (dc&(SQLITE_IOCAP_ATOMIC|(nPage>>8))&&nSector<=nPage) ){
+ if( !fd->pMethods ||
+ (dc & (SQLITE_IOCAP_ATOMIC|(szPage>>8)) && nSector<=szPage) ){
return JOURNAL_HDR_SZ(pPager) + JOURNAL_PG_SZ(pPager);
}
return 0;
@@ -1294,7 +1295,7 @@ static void pager_reset(Pager *pPager){
PAGER_INCR(sqlite3_pager_pgfree_count);
pNext = pPg->pNextAll;
lruListRemove(pPg);
- sqlite3_free(pPg->pData);
+ sqlite3PageFree(pPg->pData);
sqlite3_free(pPg);
}
assert(pPager->lru.pFirst==0);
@@ -2180,7 +2181,7 @@ int sqlite3PagerOpen(
int useJournal = (flags & PAGER_OMIT_JOURNAL)==0;
int noReadlock = (flags & PAGER_NO_READLOCK)!=0;
int journalFileSize = sqlite3JournalSize(pVfs);
- int nDefaultPage = SQLITE_DEFAULT_PAGE_SIZE;
+ int szPageDflt = SQLITE_DEFAULT_PAGE_SIZE;
char *zPathname = 0;
int nPathname = 0;
@@ -2259,8 +2260,8 @@ int sqlite3PagerOpen(
*/
if( rc==SQLITE_OK && !readOnly ){
int iSectorSize = sqlite3OsSectorSize(pPager->fd);
- if( nDefaultPage<iSectorSize ){
- nDefaultPage = iSectorSize;
+ if( szPageDflt<iSectorSize ){
+ szPageDflt = iSectorSize;
}
#ifdef SQLITE_ENABLE_ATOMIC_WRITE
{
@@ -2269,13 +2270,13 @@ int sqlite3PagerOpen(
assert(SQLITE_IOCAP_ATOMIC512==(512>>8));
assert(SQLITE_IOCAP_ATOMIC64K==(65536>>8));
assert(SQLITE_MAX_DEFAULT_PAGE_SIZE<=65536);
- for(ii=nDefaultPage; ii<=SQLITE_MAX_DEFAULT_PAGE_SIZE; ii=ii*2){
- if( iDc&(SQLITE_IOCAP_ATOMIC|(ii>>8)) ) nDefaultPage = ii;
+ for(ii=szPageDflt; ii<=SQLITE_MAX_DEFAULT_PAGE_SIZE; ii=ii*2){
+ if( iDc&(SQLITE_IOCAP_ATOMIC|(ii>>8)) ) szPageDflt = ii;
}
}
#endif
- if( nDefaultPage>SQLITE_MAX_DEFAULT_PAGE_SIZE ){
- nDefaultPage = SQLITE_MAX_DEFAULT_PAGE_SIZE;
+ if( szPageDflt>SQLITE_MAX_DEFAULT_PAGE_SIZE ){
+ szPageDflt = SQLITE_MAX_DEFAULT_PAGE_SIZE;
}
}
}
@@ -2289,7 +2290,7 @@ int sqlite3PagerOpen(
}
if( pPager && rc==SQLITE_OK ){
- pPager->pTmpSpace = sqlite3MallocZero(nDefaultPage);
+ pPager->pTmpSpace = sqlite3PageMalloc(szPageDflt);
}
/* If an error occured in either of the blocks above.
@@ -2326,7 +2327,7 @@ int sqlite3PagerOpen(
/* pPager->stmtInUse = 0; */
/* pPager->nRef = 0; */
pPager->dbSize = memDb-1;
- pPager->pageSize = nDefaultPage;
+ pPager->pageSize = szPageDflt;
/* pPager->stmtSize = 0; */
/* pPager->stmtJSize = 0; */
/* pPager->nPage = 0; */
@@ -2421,7 +2422,7 @@ int sqlite3PagerSetPagesize(Pager *pPager, u16 *pPageSize){
if( pageSize && pageSize!=pPager->pageSize
&& !pPager->memDb && pPager->nRef==0
){
- char *pNew = (char *)sqlite3Malloc(pageSize);
+ char *pNew = (char *)sqlite3PageMalloc(pageSize);
if( !pNew ){
rc = SQLITE_NOMEM;
}else{
@@ -2429,7 +2430,7 @@ int sqlite3PagerSetPagesize(Pager *pPager, u16 *pPageSize){
pager_reset(pPager);
pPager->pageSize = pageSize;
setSectorSize(pPager);
- sqlite3_free(pPager->pTmpSpace);
+ sqlite3PageFree(pPager->pTmpSpace);
pPager->pTmpSpace = pNew;
pagerLeave(pPager);
}
@@ -2567,8 +2568,8 @@ int sqlite3PagerPagecount(Pager *pPager, int *pnPage){
** Clear a PgHistory block
*/
static void clearHistory(PgHistory *pHist){
- sqlite3_free(pHist->pOrig);
- sqlite3_free(pHist->pStmt);
+ sqlite3PageFree(pHist->pOrig);
+ sqlite3PageFree(pHist->pStmt);
pHist->pOrig = 0;
pHist->pStmt = 0;
}
@@ -2653,7 +2654,7 @@ static void pager_truncate_cache(Pager *pPager){
PAGER_INCR(sqlite3_pager_pgfree_count);
unlinkPage(pPg);
makeClean(pPg);
- sqlite3_free(pPg->pData);
+ sqlite3PageFree(pPg->pData);
sqlite3_free(pPg);
pPager->nPage--;
}
@@ -2790,7 +2791,7 @@ int sqlite3PagerClose(Pager *pPager){
*/
sqlite3_free(pPager->aHash);
- sqlite3_free(pPager->pTmpSpace);
+ sqlite3PageFree(pPager->pTmpSpace);
sqlite3_free(pPager);
return SQLITE_OK;
}
@@ -3347,7 +3348,7 @@ int sqlite3PagerReleaseMemory(int nReq){
);
IOTRACE(("PGFREE %p %d *\n", pPager, pPg->pgno));
PAGER_INCR(sqlite3_pager_pgfree_count);
- sqlite3_free(pPg->pData);
+ sqlite3PageFree(pPg->pData);
sqlite3_free(pPg);
pPager->nPage--;
}else{
@@ -3649,7 +3650,7 @@ static int pagerAllocatePage(Pager *pPager, PgHdr **ppPg){
+ MEMDB*sizeof(PgHistory);
pPg = sqlite3Malloc( nByteHdr );
if( pPg ){
- pData = sqlite3Malloc( pPager->pageSize );
+ pData = sqlite3PageMalloc( pPager->pageSize );
if( pData==0 ){
sqlite3_free(pPg);
pPg = 0;
@@ -4223,7 +4224,7 @@ static int pager_write(PgHdr *pPg){
PgHistory *pHist = PGHDR_TO_HIST(pPg, pPager);
PAGERTRACE3("JOURNAL %d page %d\n", PAGERID(pPager), pPg->pgno);
assert( pHist->pOrig==0 );
- pHist->pOrig = sqlite3Malloc( pPager->pageSize );
+ pHist->pOrig = sqlite3PageMalloc( pPager->pageSize );
if( !pHist->pOrig ){
return SQLITE_NOMEM;
}
@@ -4293,7 +4294,7 @@ static int pager_write(PgHdr *pPg){
if( MEMDB ){
PgHistory *pHist = PGHDR_TO_HIST(pPg, pPager);
assert( pHist->pStmt==0 );
- pHist->pStmt = sqlite3Malloc( pPager->pageSize );
+ pHist->pStmt = sqlite3PageMalloc( pPager->pageSize );
if( pHist->pStmt ){
memcpy(pHist->pStmt, PGHDR_TO_DATA(pPg), pPager->pageSize);
}
@@ -5035,7 +5036,7 @@ int sqlite3PagerStmtCommit(Pager *pPager){
assert( pHist->inStmt );
pHist->inStmt = 0;
pHist->pPrevStmt = pHist->pNextStmt = 0;
- sqlite3_free(pHist->pStmt);
+ sqlite3PageFree(pHist->pStmt);
pHist->pStmt = 0;
}
}
@@ -5063,7 +5064,7 @@ int sqlite3PagerStmtRollback(Pager *pPager){
pHist = PGHDR_TO_HIST(pPg, pPager);
if( pHist->pStmt ){
memcpy(PGHDR_TO_DATA(pPg), pHist->pStmt, pPager->pageSize);
- sqlite3_free(pHist->pStmt);
+ sqlite3PageFree(pHist->pStmt);
pHist->pStmt = 0;
}
}
diff --git a/src/sqlite.h.in b/src/sqlite.h.in
index ca26f2c71..52e7f5537 100644
--- a/src/sqlite.h.in
+++ b/src/sqlite.h.in
@@ -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.328 2008/06/15 02:51:48 drh Exp $
+** @(#) $Id: sqlite.h.in,v 1.329 2008/06/17 15:12:01 drh Exp $
*/
#ifndef _SQLITE3_H_
#define _SQLITE3_H_
@@ -975,15 +975,7 @@ int sqlite3_config(int, ...);
** The xRoundup method returns what would be the allocated size of
** a memory allocation given a particular requested size. Most memory
** allocators round up memory allocations at least to the next multiple
-** of 8. Some round up to a larger multiple or to a power of 2.
-**
-** The xTempMalloc and xTempFree methods are used to allocate a large
-** chunk of temporary-use memory whose lifetime is a single procedure
-** call. These routines may be the same as xMalloc and xFree, if desired,
-** though some specialized applications may benefit from using a different
-** allocation algorithm in this case.
-** SQLite will never request more than one outstanding memory allocation
-** per thread using xTempMalloc.
+** of 8. Some allocators round up to a larger multiple or to a power of 2.
**
** The xInit method initializes the memory allocator. (For example,
** it might allocate any require mutexes or initialize internal data
@@ -999,8 +991,6 @@ struct sqlite3_mem_methods {
void *(*xRealloc)(void*,int); /* Resize an allocation */
int (*xSize)(void*); /* Return the size of an allocation */
int (*xRoundup)(int); /* Round up request size to allocation size */
- void *(*xTempMalloc)(int); /* Allocate temporary space */
- void (*xTempFree)(void*); /* Free space from xTempMalloc */
int (*xInit)(void*); /* Initialize the memory allocator */
void (*xShutdown)(void*); /* Deinitialize the memory allocator */
void *pAppData; /* Argument to xInit() and xShutdown() */
diff --git a/src/sqliteInt.h b/src/sqliteInt.h
index cccc29e77..e0b9c4c05 100644
--- a/src/sqliteInt.h
+++ b/src/sqliteInt.h
@@ -11,7 +11,7 @@
*************************************************************************
** Internal interface definitions for SQLite.
**
-** @(#) $Id: sqliteInt.h,v 1.710 2008/06/15 02:51:48 drh Exp $
+** @(#) $Id: sqliteInt.h,v 1.711 2008/06/17 15:12:01 drh Exp $
*/
#ifndef _SQLITEINT_H_
#define _SQLITEINT_H_
@@ -1791,8 +1791,10 @@ void *sqlite3Realloc(void*, int);
void *sqlite3DbReallocOrFree(sqlite3 *, void *, int);
void *sqlite3DbRealloc(sqlite3 *, void *, int);
int sqlite3MallocSize(void *);
-void *sqlite3TempMalloc(int);
-void sqlite3TempFree(void*);
+void *sqlite3ScratchMalloc(int);
+void sqlite3ScratchFree(void*);
+void *sqlite3PageMalloc(int);
+void sqlite3PageFree(void*);
void sqlite3MemSetDefault(void);
int sqlite3IsNaN(double);