-C Updates\sto\smem6.c\sallocator.\s(CVS\s5473)
-D 2008-07-25T08:49:00
+C Change\smem6.c\sto\suse\sthe\smalloc()\sand\sfree()\sfunctions\sdirectly,\sinstead\sof\sgoing\svia\sanother\ssqlite3_mem_methods\sstructure.\s(CVS\s5474)
+D 2008-07-25T09:24:13
F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0
F Makefile.in 77ff156061bb870aa0a8b3d545c670d08070f7e6
F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
F src/mem3.c c73e935d0b900abc51d5fa45f880937b062f4a9f
F src/mem4.c 6703adb1717b26d9d70a1c2586b4b7b7ffee7909
F src/mem5.c 0b0ba1c2a02d86eb812dea6debacee841e3856f7
-F src/mem6.c 1edd29bdd837682c54d0836fa426abfb8f838d67
+F src/mem6.c 52b0812f666a387b8b3e4528c60f6003708a2172
F src/mutex.c a485a0eac8ee2cd95f66e565b4c6696c18db968f
F src/mutex.h e52ffa1dfc6a6077e8b1823d2c2b7dfcbcf85594
F src/mutex_os2.c 9c5637aa4c307c552566d0f0b3bd206245b54a97
F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
F tool/speedtest8.c 1dbced29de5f59ba2ebf877edcadf171540374d1
F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
-P 599a9dea8fc97d0e7f09e67c9954de8cc1b8748e
-R ce0b42684f54a70ca69065b71071d9d4
+P 43a4cae2acea33d1a17c0037516e9c27fb7e8e91
+R 6b9773f158bf3ee83a8701deeafc08e6
U danielk1977
-Z 80afc91241769621e2af3603082ce4f6
+Z 8490bacca10c0ed9d136bc3e11db83be
*************************************************************************
**
** This file contains an alternative memory allocation system for SQLite.
-** This system is implemented as a wrapper around the default memory
-** allocation system (usually the one found in mem1.c - system malloc).
+** This system is implemented as a wrapper around the system provided
+** by the operating system - vanilla malloc(), realloc() and free().
**
** This system differentiates between requests for "small" allocations
** (by default those of 128 bytes or less) and "large" allocations (all
** others). The 256 byte threshhold is configurable at runtime.
**
-** All requests for large allocations are passed through to the
-** default memory allocation system.
+** All requests for large allocations are passed through to the
+** default system.
**
** Requests for small allocations are met by allocating space within
** one or more larger "chunks" of memory obtained from the default
** fragmentation. On some systems, heap fragmentation can cause a
** significant real-time slowdown.
**
-** $Id: mem6.c,v 1.3 2008/07/25 08:49:00 danielk1977 Exp $
+** $Id: mem6.c,v 1.4 2008/07/25 09:24:13 danielk1977 Exp $
*/
#ifdef SQLITE_ENABLE_MEMSYS6
}
struct Mem6Global {
- sqlite3_mem_methods parent; /* Used to allocate chunks */
int nMinAlloc; /* Minimum allowed allocation size */
- int nThreshold; /* Allocs larger than this go to parent */
+ int nThreshold; /* Allocs larger than this go to malloc() */
sqlite3_mutex *mutex;
Mem6Chunk *pChunk; /* Singly linked list of all memory chunks */
} mem6;
** the size of the next chunk to allocate, in bytes.
*/
static int nextChunkSize(void){
- int iTotal = 0;
+ int iTotal = MIN_CHUNKSIZE;
Mem6Chunk *p;
for(p=mem6.pChunk; p; p=p->pNext){
- iTotal += mem6.parent.xSize((void *)p);
- }
- if( iTotal==0 ){
- iTotal = MIN_CHUNKSIZE;
+ iTotal = iTotal*2;
}
return iTotal;
}
Mem6Chunk **pp = &mem6.pChunk;
for( pp=&mem6.pChunk; *pp!=pChunk; pp = &(*pp)->pNext );
*pp = (*pp)->pNext;
- mem6.parent.xFree(pChunk);
+ free(pChunk);
}
static void *memsys6Malloc(int nByte){
Mem6Chunk *pChunk;
void *p = 0;
+ int nTotal = nByte+8;
mem6Enter();
- if( nByte>mem6.nThreshold ){
- p = mem6.parent.xMalloc(nByte);
+ if( nTotal>mem6.nThreshold ){
+ p = malloc(nTotal);
}else{
for(pChunk=mem6.pChunk; !p && pChunk; pChunk=pChunk->pNext){
- p = chunkMalloc(pChunk, nByte);
+ p = chunkMalloc(pChunk, nTotal);
}
if( !p ){
int iSize = nextChunkSize();
- p = mem6.parent.xMalloc(iSize);
+ p = malloc(iSize);
if( p ){
pChunk = chunkInit((u8 *)p, iSize, mem6.nMinAlloc);
pChunk->pNext = mem6.pChunk;
mem6.pChunk = pChunk;
- p = chunkMalloc(pChunk, nByte);
+ p = chunkMalloc(pChunk, nTotal);
assert(p);
}
}
}
mem6Leave();
- return p;
+ ((sqlite3_int64 *)p)[0] = nByte;
+ return &((sqlite3_int64 *)p)[1];
}
-static int memsys6Size(void *p){
- Mem6Chunk *pChunk;
- int iSize;
- mem6Enter();
- pChunk = findChunk(p);
- iSize = (pChunk ? chunkSize(pChunk, p) : mem6.parent.xSize(p));
- mem6Leave();
- return iSize;
+static int memsys6Size(void *pPrior){
+ sqlite3_int64 *p;
+ if( pPrior==0 ) return 0;
+ p = (sqlite3_int64*)pPrior;
+ p--;
+ return p[0];
}
-static void memsys6Free(void *p){
+static void memsys6Free(void *pPrior){
Mem6Chunk *pChunk;
+ void *p = &((sqlite3_int64 *)pPrior)[-1];
mem6Enter();
pChunk = findChunk(p);
freeChunk(pChunk);
}
}else{
- mem6.parent.xFree(p);
+ free(p);
}
mem6Leave();
}
static int memsys6Init(void *pCtx){
u8 bMemstat = sqlite3Config.bMemstat;
- mem6.parent = *sqlite3MemGetDefault();
mem6.nMinAlloc = 16;
mem6.pChunk = 0;
mem6.nThreshold = sqlite3Config.nSmall;
mem6.mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MEM);
}
- /* Initialize the parent allocator. */
-#ifdef SQLITE_MEMDEBUG
- sqlite3Config.bMemstat = 1;
-#endif
- mem6.parent.xInit(mem6.parent.pAppData);
-#ifdef SQLITE_MEMDEBUG
- sqlite3Config.bMemstat = bMemstat;
-#endif
-
return SQLITE_OK;
}
static void memsys6Shutdown(void *pCtx){
- if( mem6.parent.xShutdown ){
- mem6.parent.xShutdown(mem6.parent.pAppData);
- }
memset(&mem6, 0, sizeof(mem6));
}