diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/malloc.c | 8 | ||||
-rw-r--r-- | src/mem3.c | 47 |
2 files changed, 31 insertions, 24 deletions
diff --git a/src/malloc.c b/src/malloc.c index 317061c1f..86ba2be96 100644 --- a/src/malloc.c +++ b/src/malloc.c @@ -12,7 +12,7 @@ ** ** Memory allocation functions used throughout sqlite. ** -** $Id: malloc.c,v 1.28 2008/07/14 12:38:21 drh Exp $ +** $Id: malloc.c,v 1.29 2008/07/18 18:56:17 drh Exp $ */ #include "sqliteInt.h" #include <stdarg.h> @@ -224,7 +224,10 @@ static int mallocWithAlarm(int n, void **pp){ sqlite3MallocAlarm(nFull); p = sqlite3Config.m.xMalloc(nFull); } - if( p ) sqlite3StatusAdd(SQLITE_STATUS_MEMORY_USED, nFull); + if( p ){ + nFull = sqlite3MallocSize(p); + sqlite3StatusAdd(SQLITE_STATUS_MEMORY_USED, nFull); + } *pp = p; return nFull; } @@ -504,6 +507,7 @@ void *sqlite3Realloc(void *pOld, int nBytes){ pNew = sqlite3Config.m.xRealloc(pOld, nNew); } if( pNew ){ + nNew = sqlite3MallocSize(pNew); sqlite3StatusAdd(SQLITE_STATUS_MEMORY_USED, nNew-nOld); } } diff --git a/src/mem3.c b/src/mem3.c index e276adef3..46a58982a 100644 --- a/src/mem3.c +++ b/src/mem3.c @@ -23,7 +23,7 @@ ** This version of the memory allocation subsystem is included ** in the build only if SQLITE_ENABLE_MEMSYS3 is defined. ** -** $Id: mem3.c,v 1.19 2008/07/16 12:25:32 drh Exp $ +** $Id: mem3.c,v 1.20 2008/07/18 18:56:17 drh Exp $ */ #include "sqliteInt.h" @@ -138,7 +138,6 @@ static struct { */ u32 nPool; Mem3Block *aPool; - /* Mem3Block aPool[SQLITE_MEMORY_SIZE/sizeof(Mem3Block)+2]; */ } mem3; /* @@ -471,6 +470,30 @@ void memsys3FreeUnsafe(void *pOld){ } /* +** Return the size of an outstanding allocation, in bytes. The +** size returned omits the 8-byte header overhead. This only +** works for chunks that are currently checked out. +*/ +static int memsys3Size(void *p){ + Mem3Block *pBlock; + if( p==0 ) return 0; + pBlock = (Mem3Block*)p; + assert( (pBlock[-1].u.hdr.size4x&1)!=0 ); + return (pBlock[-1].u.hdr.size4x&~3)*2 - 4; +} + +/* +** Round up a request size to the next valid allocation size. +*/ +static int memsys3Roundup(int n){ + if( n<=12 ){ + return 12; + }else{ + return ((n+11)&~7) - 4; + } +} + +/* ** Allocate nBytes of memory. */ static void *memsys3Malloc(int nBytes){ @@ -493,19 +516,6 @@ void memsys3Free(void *pPrior){ } /* -** Return the size of an outstanding allocation, in bytes. The -** size returned omits the 8-byte header overhead. This only -** works for chunks that are currently checked out. -*/ -static int memsys3Size(void *p){ - Mem3Block *pBlock; - if( p==0 ) return 0; - pBlock = (Mem3Block*)p; - assert( (pBlock[-1].u.hdr.size4x&1)!=0 ); - return (pBlock[-1].u.hdr.size4x&~3)*2 - 4; -} - -/* ** Change the size of an existing memory allocation */ void *memsys3Realloc(void *pPrior, int nBytes){ @@ -537,13 +547,6 @@ void *memsys3Realloc(void *pPrior, int nBytes){ } /* -** Round up a request size to the next valid allocation size. -*/ -static int memsys3Roundup(int n){ - return (n+7) & ~7; -} - -/* ** Initialize this module. */ static int memsys3Init(void *NotUsed){ |