Lines Matching defs:mem3

27464 /************** Begin file mem3.c ********************************************/
27529 ** We often identify a chunk by its index in mem3.aPool[]. When
27537 ** Pointers to the head of the list are stored in mem3.aiSmall[]
27538 ** for smaller chunks and mem3.aiHash[] for larger chunks.
27552 u32 next; /* Index in mem3.aPool[] of next free chunk */
27553 u32 prev; /* Index in mem3.aPool[] of previous free chunk */
27560 ** into a single structure named "mem3". This is to keep the
27603 } mem3 = { 97535575 };
27605 #define mem3 GLOBAL(struct Mem3Global, mem3)
27608 ** Unlink the chunk at mem3.aPool[i] from list it is currently
27612 u32 next = mem3.aPool[i].u.list.next;
27613 u32 prev = mem3.aPool[i].u.list.prev;
27614 assert( sqlite3_mutex_held(mem3.mutex) );
27618 mem3.aPool[prev].u.list.next = next;
27621 mem3.aPool[next].u.list.prev = prev;
27623 mem3.aPool[i].u.list.next = 0;
27624 mem3.aPool[i].u.list.prev = 0;
27633 assert( sqlite3_mutex_held(mem3.mutex) );
27634 assert( (mem3.aPool[i-1].u.hdr.size4x & 1)==0 );
27636 size = mem3.aPool[i-1].u.hdr.size4x/4;
27637 assert( size==mem3.aPool[i+size-1].u.hdr.prevSize );
27640 memsys3UnlinkFromList(i, &mem3.aiSmall[size-2]);
27643 memsys3UnlinkFromList(i, &mem3.aiHash[hash]);
27648 ** Link the chunk at mem3.aPool[i] so that is on the list rooted
27652 assert( sqlite3_mutex_held(mem3.mutex) );
27653 mem3.aPool[i].u.list.next = *pRoot;
27654 mem3.aPool[i].u.list.prev = 0;
27656 mem3.aPool[*pRoot].u.list.prev = i;
27667 assert( sqlite3_mutex_held(mem3.mutex) );
27669 assert( (mem3.aPool[i-1].u.hdr.size4x & 1)==0 );
27670 size = mem3.aPool[i-1].u.hdr.size4x/4;
27671 assert( size==mem3.aPool[i+size-1].u.hdr.prevSize );
27674 memsys3LinkIntoList(i, &mem3.aiSmall[size-2]);
27677 memsys3LinkIntoList(i, &mem3.aiHash[hash]);
27687 if( sqlite3GlobalConfig.bMemstat==0 && mem3.mutex==0 ){
27688 mem3.mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MEM);
27690 sqlite3_mutex_enter(mem3.mutex);
27693 sqlite3_mutex_leave(mem3.mutex);
27700 if( !mem3.alarmBusy ){
27701 mem3.alarmBusy = 1;
27702 assert( sqlite3_mutex_held(mem3.mutex) );
27703 sqlite3_mutex_leave(mem3.mutex);
27705 sqlite3_mutex_enter(mem3.mutex);
27706 mem3.alarmBusy = 0;
27718 assert( sqlite3_mutex_held(mem3.mutex) );
27720 assert( mem3.aPool[i-1].u.hdr.size4x/4==nBlock );
27721 assert( mem3.aPool[i+nBlock-1].u.hdr.prevSize==nBlock );
27722 x = mem3.aPool[i-1].u.hdr.size4x;
27723 mem3.aPool[i-1].u.hdr.size4x = nBlock*4 | 1 | (x&2);
27724 mem3.aPool[i+nBlock-1].u.hdr.prevSize = nBlock;
27725 mem3.aPool[i+nBlock-1].u.hdr.size4x |= 2;
27726 return &mem3.aPool[i];
27730 ** Carve a piece off of the end of the mem3.iKeyBlk free chunk.
27735 assert( sqlite3_mutex_held(mem3.mutex) );
27736 assert( mem3.szKeyBlk>=nBlock );
27737 if( nBlock>=mem3.szKeyBlk-1 ){
27739 void *p = memsys3Checkout(mem3.iKeyBlk, mem3.szKeyBlk);
27740 mem3.iKeyBlk = 0;
27741 mem3.szKeyBlk = 0;
27742 mem3.mnKeyBlk = 0;
27747 newi = mem3.iKeyBlk + mem3.szKeyBlk - nBlock;
27748 assert( newi > mem3.iKeyBlk+1 );
27749 mem3.aPool[mem3.iKeyBlk+mem3.szKeyBlk-1].u.hdr.prevSize = nBlock;
27750 mem3.aPool[mem3.iKeyBlk+mem3.szKeyBlk-1].u.hdr.size4x |= 2;
27751 mem3.aPool[newi-1].u.hdr.size4x = nBlock*4 + 1;
27752 mem3.szKeyBlk -= nBlock;
27753 mem3.aPool[newi-1].u.hdr.prevSize = mem3.szKeyBlk;
27754 x = mem3.aPool[mem3.iKeyBlk-1].u.hdr.size4x & 2;
27755 mem3.aPool[mem3.iKeyBlk-1].u.hdr.size4x = mem3.szKeyBlk*4 | x;
27756 if( mem3.szKeyBlk < mem3.mnKeyBlk ){
27757 mem3.mnKeyBlk = mem3.szKeyBlk;
27759 return (void*)&mem3.aPool[newi];
27766 ** mem3.aiSmall[] or mem3.aiHash[].
27771 ** If it sees a chunk that is larger than mem3.iKeyBlk, it replaces
27772 ** the current mem3.iKeyBlk with the new larger chunk. In order for
27773 ** this mem3.iKeyBlk replacement to work, the key chunk must be
27782 assert( sqlite3_mutex_held(mem3.mutex) );
27784 iNext = mem3.aPool[i].u.list.next;
27785 size = mem3.aPool[i-1].u.hdr.size4x;
27789 assert( i > mem3.aPool[i-1].u.hdr.prevSize );
27790 prev = i - mem3.aPool[i-1].u.hdr.prevSize;
27792 iNext = mem3.aPool[prev].u.list.next;
27796 x = mem3.aPool[prev-1].u.hdr.size4x & 2;
27797 mem3.aPool[prev-1].u.hdr.size4x = size*4 | x;
27798 mem3.aPool[prev+size-1].u.hdr.prevSize = size;
27804 if( size>mem3.szKeyBlk ){
27805 mem3.iKeyBlk = i;
27806 mem3.szKeyBlk = size;
27823 assert( sqlite3_mutex_held(mem3.mutex) );
27838 i = mem3.aiSmall[nBlock-2];
27840 memsys3UnlinkFromList(i, &mem3.aiSmall[nBlock-2]);
27845 for(i=mem3.aiHash[hash]; i>0; i=mem3.aPool[i].u.list.next){
27846 if( mem3.aPool[i-1].u.hdr.size4x/4==nBlock ){
27847 memsys3UnlinkFromList(i, &mem3.aiHash[hash]);
27857 if( mem3.szKeyBlk>=nBlock ){
27869 for(toFree=nBlock*16; toFree<(mem3.nPool*16); toFree *= 2){
27871 if( mem3.iKeyBlk ){
27872 memsys3Link(mem3.iKeyBlk);
27873 mem3.iKeyBlk = 0;
27874 mem3.szKeyBlk = 0;
27877 memsys3Merge(&mem3.aiHash[i]);
27880 memsys3Merge(&mem3.aiSmall[i]);
27882 if( mem3.szKeyBlk ){
27883 memsys3Unlink(mem3.iKeyBlk);
27884 if( mem3.szKeyBlk>=nBlock ){
27904 assert( sqlite3_mutex_held(mem3.mutex) );
27905 assert( p>mem3.aPool && p<&mem3.aPool[mem3.nPool] );
27906 i = p - mem3.aPool;
27907 assert( (mem3.aPool[i-1].u.hdr.size4x&1)==1 );
27908 size = mem3.aPool[i-1].u.hdr.size4x/4;
27909 assert( i+size<=mem3.nPool+1 );
27910 mem3.aPool[i-1].u.hdr.size4x &= ~1;
27911 mem3.aPool[i+size-1].u.hdr.prevSize = size;
27912 mem3.aPool[i+size-1].u.hdr.size4x &= ~2;
27916 if( mem3.iKeyBlk ){
27917 while( (mem3.aPool[mem3.iKeyBlk-1].u.hdr.size4x&2)==0 ){
27918 size = mem3.aPool[mem3.iKeyBlk-1].u.hdr.prevSize;
27919 mem3.iKeyBlk -= size;
27920 mem3.szKeyBlk += size;
27921 memsys3Unlink(mem3.iKeyBlk);
27922 x = mem3.aPool[mem3.iKeyBlk-1].u.hdr.size4x & 2;
27923 mem3.aPool[mem3.iKeyBlk-1].u.hdr.size4x = mem3.szKeyBlk*4 | x;
27924 mem3.aPool[mem3.iKeyBlk+mem3.szKeyBlk-1].u.hdr.prevSize = mem3.szKeyBlk;
27926 x = mem3.aPool[mem3.iKeyBlk-1].u.hdr.size4x & 2;
27927 while( (mem3.aPool[mem3.iKeyBlk+mem3.szKeyBlk-1].u.hdr.size4x&1)==0 ){
27928 memsys3Unlink(mem3.iKeyBlk+mem3.szKeyBlk);
27929 mem3.szKeyBlk += mem3.aPool[mem3.iKeyBlk+mem3.szKeyBlk-1].u.hdr.size4x/4;
27930 mem3.aPool[mem3.iKeyBlk-1].u.hdr.size4x = mem3.szKeyBlk*4 | x;
27931 mem3.aPool[mem3.iKeyBlk+mem3.szKeyBlk-1].u.hdr.prevSize = mem3.szKeyBlk;
28022 /* Store a pointer to the memory block in global structure mem3. */
28024 mem3.aPool = (Mem3Block *)sqlite3GlobalConfig.pHeap;
28025 mem3.nPool = (sqlite3GlobalConfig.nHeap / sizeof(Mem3Block)) - 2;
28028 mem3.szKeyBlk = mem3.nPool;
28029 mem3.mnKeyBlk = mem3.szKeyBlk;
28030 mem3.iKeyBlk = 1;
28031 mem3.aPool[0].u.hdr.size4x = (mem3.szKeyBlk<<2) + 2;
28032 mem3.aPool[mem3.nPool].u.hdr.prevSize = mem3.nPool;
28033 mem3.aPool[mem3.nPool].u.hdr.size4x = 1;
28043 mem3.mutex = 0;
28070 for(i=1; i<=mem3.nPool; i+=size/4){
28071 size = mem3.aPool[i-1].u.hdr.size4x;
28073 fprintf(out, "%p size error\n", &mem3.aPool[i]);
28077 if( (size&1)==0 && mem3.aPool[i+size/4-1].u.hdr.prevSize!=size/4 ){
28078 fprintf(out, "%p tail size does not match\n", &mem3.aPool[i]);
28082 if( ((mem3.aPool[i+size/4-1].u.hdr.size4x&2)>>1)!=(size&1) ){
28083 fprintf(out, "%p tail checkout bit is incorrect\n", &mem3.aPool[i]);
28088 fprintf(out, "%p %6d bytes checked out\n", &mem3.aPool[i], (size/4)*8-8);
28090 fprintf(out, "%p %6d bytes free%s\n", &mem3.aPool[i], (size/4)*8-8,
28091 i==mem3.iKeyBlk ? " **key**" : "");
28095 if( mem3.aiSmall[i]==0 ) continue;
28097 for(j = mem3.aiSmall[i]; j>0; j=mem3.aPool[j].u.list.next){
28098 fprintf(out, " %p(%d)", &mem3.aPool[j],
28099 (mem3.aPool[j-1].u.hdr.size4x/4)*8-8);
28104 if( mem3.aiHash[i]==0 ) continue;
28106 for(j = mem3.aiHash[i]; j>0; j=mem3.aPool[j].u.list.next){
28107 fprintf(out, " %p(%d)", &mem3.aPool[j],
28108 (mem3.aPool[j-1].u.hdr.size4x/4)*8-8);
28112 fprintf(out, "key=%d\n", mem3.iKeyBlk);
28113 fprintf(out, "nowUsed=%d\n", mem3.nPool*8 - mem3.szKeyBlk*8);
28114 fprintf(out, "mxUsed=%d\n", mem3.nPool*8 - mem3.mnKeyBlk*8);
28115 sqlite3_mutex_leave(mem3.mutex);
28153 /************** End of mem3.c ************************************************/