/ Check-in [383a7860]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Added support for scratch-memory lookaside allocations. Largely untested. Added calls to sqlite3_initialize() within malloc APIs. (CVS 5237)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 383a78601c70cd832c171344857038e345b9ae5c
User & Date: drh 2008-06-18 18:12:04
Context
2008-06-18
18:57
Remove public APIs sqlite3_mutex_init() and sqlite3_mutex_end(). This commit only changes the code, documentation is not updated yet. (CVS 5238) check-in: 42a2a8f4 user: danielk1977 tags: trunk
18:12
Added support for scratch-memory lookaside allocations. Largely untested. Added calls to sqlite3_initialize() within malloc APIs. (CVS 5237) check-in: 383a7860 user: drh tags: trunk
18:08
Add a call to sqlite3_initialize() to sqlite3_mutex_alloc() (CVS 5236) check-in: 8b23b719 user: danielk1977 tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/malloc.c.

8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
..
39
40
41
42
43
44
45

46
47
48
49
50
51
52
..
81
82
83
84
85
86
87












88
89
90
91
92
93
94
..
98
99
100
101
102
103
104
105
106




















107
108
109
110
111
112
113
114
115

116
117
118
119
120
121
122

123
124
125
126
127
128
129
130
131
132
133
134
135

136
137
138
139
140
141
142
...
248
249
250
251
252
253
254

255




256
257
258
259

260
261

262
263
264


265

266

267
268
269
270

271




272
273
274




275










276
277
278
279
280
281
282
**    May you find forgiveness for yourself and forgive others.
**    May you share freely, never taking more than you give.
**
*************************************************************************
**
** Memory allocation functions used throughout sqlite.
**
** $Id: malloc.c,v 1.19 2008/06/18 17:09:10 danielk1977 Exp $
*/
#include "sqliteInt.h"
#include <stdarg.h>
#include <ctype.h>

/*
** This routine runs when the memory allocator sees that the
................................................................................
  sqlite3_uint64 iLimit;
  int overage;
  if( n<0 ){
    iLimit = 0;
  }else{
    iLimit = n;
  }

  if( iLimit>0 ){
    sqlite3_memory_alarm(softHeapLimitEnforcer, 0, iLimit);
  }else{
    sqlite3_memory_alarm(0, 0, 0);
  }
  overage = sqlite3_memory_used() - n;
  if( overage>0 ){
................................................................................
  ** callbacks.
  */
  sqlite3_int64 alarmThreshold;
  void (*alarmCallback)(void*, sqlite3_int64,int);
  void *alarmArg;
  int alarmBusy;













  /*
  ** Performance statistics
  */
  sqlite3_int64 nowUsed;  /* Main memory currently in use */
  sqlite3_int64 mxUsed;   /* Highwater mark for nowUsed */
  int mxReq;              /* Max request size for ordinary mallocs */
  int mxScratchReq;       /* Max request size for xTemp mallocs */
................................................................................
** Initialize the memory allocation subsystem.
*/
int sqlite3MallocInit(void){
  if( sqlite3Config.m.xMalloc==0 ){
    sqlite3MemSetDefault();
  }
  memset(&mem0, 0, sizeof(mem0));
  if( sqlite3Config.bMemstat ){
    mem0.mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MEM);




















  }
  return sqlite3Config.m.xInit(sqlite3Config.m.pAppData);
}

/*
** Deinitialize the memory allocation subsystem.
*/
void sqlite3MallocEnd(void){
   sqlite3Config.m.xShutdown(sqlite3Config.m.pAppData);

}

/*
** Return the amount of memory currently checked out.
*/
sqlite3_int64 sqlite3_memory_used(void){
  sqlite3_int64 n;

  sqlite3_mutex_enter(mem0.mutex);
  n = mem0.nowUsed;
  sqlite3_mutex_leave(mem0.mutex);  
  return n;
}

/*
** Return the maximum amount of memory that has ever been
** checked out since either the beginning of this process
** or since the most recent reset.
*/
sqlite3_int64 sqlite3_memory_highwater(int resetFlag){
  sqlite3_int64 n;

  sqlite3_mutex_enter(mem0.mutex);
  n = mem0.mxUsed;
  if( resetFlag ){
    mem0.mxUsed = mem0.nowUsed;
  }
  sqlite3_mutex_leave(mem0.mutex);  
  return n;
................................................................................
*/
void *sqlite3ScratchMalloc(int n){
  void *p;
  assert( n>0 );
  if( sqlite3FaultStep(SQLITE_FAULTINJECTOR_MALLOC) ){
    return 0;
  }

#if SQLITE_THREADSAFE==0 && !defined(NDEBUG)




  assert( scratchAllocOut==0 );
  scratchAllocOut = 1;
#endif
  if( sqlite3Config.bMemstat ){

    sqlite3_mutex_enter(mem0.mutex);
    if( n>mem0.mxScratchReq ) mem0.mxScratchReq = n;

    p = sqlite3Config.m.xMalloc(n);
    sqlite3_mutex_leave(mem0.mutex);
  }else{


    p = sqlite3Config.m.xMalloc(n);

  }

  return p;
}
void sqlite3ScratchFree(void *p){
  if( p ){

#if SQLITE_THREADSAFE==0 && !defined(NDEBUG)




    assert( scratchAllocOut==1 );
    scratchAllocOut = 0;
#endif




    sqlite3Config.m.xFree(p);










  }
}

/*
** Place holders for the page-cache memory allocator.
*/
void *sqlite3PageMalloc(int iSize){







|







 







>







 







>
>
>
>
>
>
>
>
>
>
>
>







 







|

>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>








|
>







>













>







 







>

>
>
>
>



<
>
|
|
>

<

>
>
|
>

>




>

>
>
>
>



>
>
>
>
|
>
>
>
>
>
>
>
>
>
>







8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
..
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
..
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
...
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
...
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299

300
301
302
303
304

305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
**    May you find forgiveness for yourself and forgive others.
**    May you share freely, never taking more than you give.
**
*************************************************************************
**
** Memory allocation functions used throughout sqlite.
**
** $Id: malloc.c,v 1.20 2008/06/18 18:12:04 drh Exp $
*/
#include "sqliteInt.h"
#include <stdarg.h>
#include <ctype.h>

/*
** This routine runs when the memory allocator sees that the
................................................................................
  sqlite3_uint64 iLimit;
  int overage;
  if( n<0 ){
    iLimit = 0;
  }else{
    iLimit = n;
  }
  sqlite3_initialize();
  if( iLimit>0 ){
    sqlite3_memory_alarm(softHeapLimitEnforcer, 0, iLimit);
  }else{
    sqlite3_memory_alarm(0, 0, 0);
  }
  overage = sqlite3_memory_used() - n;
  if( overage>0 ){
................................................................................
  ** callbacks.
  */
  sqlite3_int64 alarmThreshold;
  void (*alarmCallback)(void*, sqlite3_int64,int);
  void *alarmArg;
  int alarmBusy;

  /*
  ** Pointers to the end of sqlite3Config.pScratch and
  ** sqlite3Config.pPage to a block of memory that records
  ** which pages are available.
  */
  u32 *aScratchFree;
  u32 *aPageFree;

  /* Number of free pages for scratch and page-cache memory */
  u32 nScratchFree;
  u32 nPageFree;

  /*
  ** Performance statistics
  */
  sqlite3_int64 nowUsed;  /* Main memory currently in use */
  sqlite3_int64 mxUsed;   /* Highwater mark for nowUsed */
  int mxReq;              /* Max request size for ordinary mallocs */
  int mxScratchReq;       /* Max request size for xTemp mallocs */
................................................................................
** Initialize the memory allocation subsystem.
*/
int sqlite3MallocInit(void){
  if( sqlite3Config.m.xMalloc==0 ){
    sqlite3MemSetDefault();
  }
  memset(&mem0, 0, sizeof(mem0));
  if( sqlite3Config.bCoreMutex ){
    mem0.mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MEM);
  }
  if( sqlite3Config.pScratch && sqlite3Config.szScratch>=3000
      && sqlite3Config.nScratch>0 ){
    int i;
    mem0.aScratchFree = (u32*)&((char*)sqlite3Config.pScratch)
                  [sqlite3Config.szScratch*sqlite3Config.nScratch];
    for(i=0; i<sqlite3Config.nScratch; i++){ mem0.aScratchFree[i] = i; }
    mem0.nScratchFree = sqlite3Config.nScratch;
  }else{
    sqlite3Config.pScratch = 0;
  }
  if( sqlite3Config.pPage && sqlite3Config.szPage>=512
      && sqlite3Config.nPage>0 ){
    int i;
    mem0.aPageFree = (u32*)&((char*)sqlite3Config.pPage)
                  [sqlite3Config.szPage*sqlite3Config.nPage];
    for(i=0; i<sqlite3Config.nPage; i++){ mem0.aPageFree[i] = i; }
    mem0.nPageFree = sqlite3Config.nPage;
  }else{
    sqlite3Config.pPage = 0;
  }
  return sqlite3Config.m.xInit(sqlite3Config.m.pAppData);
}

/*
** Deinitialize the memory allocation subsystem.
*/
void sqlite3MallocEnd(void){
  sqlite3Config.m.xShutdown(sqlite3Config.m.pAppData);
  memset(&mem0, 0, sizeof(mem0));
}

/*
** Return the amount of memory currently checked out.
*/
sqlite3_int64 sqlite3_memory_used(void){
  sqlite3_int64 n;
  sqlite3_initialize();
  sqlite3_mutex_enter(mem0.mutex);
  n = mem0.nowUsed;
  sqlite3_mutex_leave(mem0.mutex);  
  return n;
}

/*
** Return the maximum amount of memory that has ever been
** checked out since either the beginning of this process
** or since the most recent reset.
*/
sqlite3_int64 sqlite3_memory_highwater(int resetFlag){
  sqlite3_int64 n;
  sqlite3_initialize();
  sqlite3_mutex_enter(mem0.mutex);
  n = mem0.mxUsed;
  if( resetFlag ){
    mem0.mxUsed = mem0.nowUsed;
  }
  sqlite3_mutex_leave(mem0.mutex);  
  return n;
................................................................................
*/
void *sqlite3ScratchMalloc(int n){
  void *p;
  assert( n>0 );
  if( sqlite3FaultStep(SQLITE_FAULTINJECTOR_MALLOC) ){
    return 0;
  }

#if SQLITE_THREADSAFE==0 && !defined(NDEBUG)
  /* Verify that no more than one scratch allocation per thread
  ** is outstanding at one time.  (This is only checked in the
  ** single-threaded case since checking in the multi-threaded case
  ** would be much more complicated.) */
  assert( scratchAllocOut==0 );
  scratchAllocOut = 1;
#endif


  sqlite3_mutex_enter(mem0.mutex);
  if( n>mem0.mxScratchReq ) mem0.mxScratchReq = n;
  if( mem0.nScratchFree==0 || sqlite3Config.szScratch>=n ){
    p = sqlite3Config.m.xMalloc(n);

  }else{
    int i;
    i = mem0.aScratchFree[--mem0.nScratchFree];
    i *= sqlite3Config.szScratch;
    p = (void*)&((char*)sqlite3Config.pScratch)[i];
  }
  sqlite3_mutex_leave(mem0.mutex);
  return p;
}
void sqlite3ScratchFree(void *p){
  if( p ){

#if SQLITE_THREADSAFE==0 && !defined(NDEBUG)
    /* Verify that no more than one scratch allocation per thread
    ** is outstanding at one time.  (This is only checked in the
    ** single-threaded case since checking in the multi-threaded case
    ** would be much more complicated.) */
    assert( scratchAllocOut==1 );
    scratchAllocOut = 0;
#endif

    if( sqlite3Config.pScratch==0
       || p<sqlite3Config.pScratch
       || p>=(void*)mem0.aScratchFree ){
      sqlite3Config.m.xFree(p);
    }else{
      int i;
      sqlite3_mutex_enter(mem0.mutex);
      assert( mem0.nScratchFree<sqlite3Config.nScratch );
      i = p - sqlite3Config.pScratch;
      i /= sqlite3Config.szScratch;
      assert( i>=0 && i<sqlite3Config.nScratch );
      mem0.aScratchFree[mem0.nScratchFree++] = i;
      sqlite3_mutex_leave(mem0.mutex);
    }
  }
}

/*
** Place holders for the page-cache memory allocator.
*/
void *sqlite3PageMalloc(int iSize){

Changes to src/sqlite.h.in.

26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
....
1051
1052
1053
1054
1055
1056
1057
1058

1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073

1074
1075
1076
1077
1078
1079
1080
1081
** on how SQLite interfaces are suppose to operate.
**
** The name of this file under configuration management is "sqlite.h.in".
** The makefile makes some minor changes to this file (such as inserting
** the version number) and changes its name to "sqlite3.h" as
** part of the build process.
**
** @(#) $Id: sqlite.h.in,v 1.334 2008/06/18 13:47:04 drh Exp $
*/
#ifndef _SQLITE3_H_
#define _SQLITE3_H_
#include <stdarg.h>     /* Needed for the definition of va_list */

/*
** Make sure we can call this stuff from C++.
................................................................................
**   <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>
**







|







 







|
>
|













|
>
|







26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
....
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
** on how SQLite interfaces are suppose to operate.
**
** The name of this file under configuration management is "sqlite.h.in".
** The makefile makes some minor changes to this file (such as inserting
** the version number) and changes its name to "sqlite3.h" as
** part of the build process.
**
** @(#) $Id: sqlite.h.in,v 1.335 2008/06/18 18:12:04 drh Exp $
*/
#ifndef _SQLITE3_H_
#define _SQLITE3_H_
#include <stdarg.h>     /* Needed for the definition of va_list */

/*
** Make sure we can call this stuff from C++.
................................................................................
**   <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 sz
** argument must be a multiple of 16. The first
** argument should point to an allocation of at least (sz+1)*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 sz
** argument must be a power of two between 512 and 32768.  The first
** argument should point to an allocation of at least (sz+4)*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>
**

Changes to src/test_malloc.c.

9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
...
646
647
648
649
650
651
652















































































653
654
655
656
657
658
659
...
668
669
670
671
672
673
674
675


676
677
678
679
680
681
682
**    May you share freely, never taking more than you give.
**
*************************************************************************
**
** This file contains code used to implement test interfaces to the
** memory allocation subsystem.
**
** $Id: test_malloc.c,v 1.23 2008/05/29 02:57:48 shane Exp $
*/
#include "sqliteInt.h"
#include "tcl.h"
#include <stdlib.h>
#include <string.h>
#include <assert.h>

................................................................................
#endif
      break;
    }
  }

  return TCL_OK;
}
















































































/*
** Register commands with the TCL interpreter.
*/
int Sqlitetest_malloc_Init(Tcl_Interp *interp){
  static struct {
     char *zName;
................................................................................
     { "sqlite3_memory_highwater",   test_memory_highwater         },
     { "sqlite3_memdebug_backtrace", test_memdebug_backtrace       },
     { "sqlite3_memdebug_dump",      test_memdebug_dump            },
     { "sqlite3_memdebug_fail",      test_memdebug_fail            },
     { "sqlite3_memdebug_pending",   test_memdebug_pending         },
     { "sqlite3_memdebug_settitle",  test_memdebug_settitle        },
     { "sqlite3_memdebug_malloc_count", test_memdebug_malloc_count },
     { "sqlite3_memdebug_log",       test_memdebug_log },


  };
  int i;
  for(i=0; i<sizeof(aObjCmd)/sizeof(aObjCmd[0]); i++){
    Tcl_CreateObjCommand(interp, aObjCmd[i].zName, aObjCmd[i].xProc, 0, 0);
  }
  return TCL_OK;
}







|







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







|
>
>







9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
...
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
...
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
**    May you share freely, never taking more than you give.
**
*************************************************************************
**
** This file contains code used to implement test interfaces to the
** memory allocation subsystem.
**
** $Id: test_malloc.c,v 1.24 2008/06/18 18:12:04 drh Exp $
*/
#include "sqliteInt.h"
#include "tcl.h"
#include <stdlib.h>
#include <string.h>
#include <assert.h>

................................................................................
#endif
      break;
    }
  }

  return TCL_OK;
}

/*
** Usage:    sqlite3_config_scratch SIZE N
**
** Set the scratch memory buffer using SQLITE_CONFIG_SCRATCH.
** The buffer is static and is of limited size.  N might be
** adjusted downward as needed to accomodate the requested size.
** The revised value of N is returned.
**
** A negative SIZE causes the buffer pointer to be NULL.
*/
static int test_config_scratch(
  void * clientData,
  Tcl_Interp *interp,
  int objc,
  Tcl_Obj *CONST objv[]
){
  int sz, N, rc;
  Tcl_Obj *pResult;
  static char buf[20000];
  if( objc!=3 ){
    Tcl_WrongNumArgs(interp, 1, objv, "SIZE N");
    return TCL_ERROR;
  }
  if( Tcl_GetIntFromObj(interp, objv[2], &sz) ) return TCL_ERROR;
  if( Tcl_GetIntFromObj(interp, objv[3], &N) ) return TCL_ERROR;
  if( sz<0 ){
    rc = sqlite3_config(SQLITE_CONFIG_SCRATCH, 0, 0, 0);
  }else if( sz==0 ){
    int mx = sizeof(buf)/(sz+4);
    if( N>mx ) N = mx;
    rc = sqlite3_config(SQLITE_CONFIG_SCRATCH, buf, sz, N);
  }
  pResult = Tcl_NewObj();
  Tcl_ListObjAppendElement(0, pResult, Tcl_NewIntObj(rc));
  Tcl_ListObjAppendElement(0, pResult, Tcl_NewIntObj(N));
  Tcl_SetObjResult(interp, pResult);
  return TCL_OK;
}

/*
** Usage:    sqlite3_config_pagecache SIZE N
**
** Set the page-cache memory buffer using SQLITE_CONFIG_PAGECACHE.
** The buffer is static and is of limited size.  N might be
** adjusted downward as needed to accomodate the requested size.
** The revised value of N is returned.
**
** A negative SIZE causes the buffer pointer to be NULL.
*/
static int test_config_pagecache(
  void * clientData,
  Tcl_Interp *interp,
  int objc,
  Tcl_Obj *CONST objv[]
){
  int sz, N, rc;
  Tcl_Obj *pResult;
  static char buf[100000];
  if( objc!=3 ){
    Tcl_WrongNumArgs(interp, 1, objv, "SIZE N");
    return TCL_ERROR;
  }
  if( Tcl_GetIntFromObj(interp, objv[2], &sz) ) return TCL_ERROR;
  if( Tcl_GetIntFromObj(interp, objv[3], &N) ) return TCL_ERROR;
  if( sz<0 ){
    rc = sqlite3_config(SQLITE_CONFIG_SCRATCH, 0, 0, 0);
  }else if( sz==0 ){
    int mx = sizeof(buf)/(sz+4);
    if( N>mx ) N = mx;
    rc = sqlite3_config(SQLITE_CONFIG_PAGECACHE, buf, sz, N);
  }
  pResult = Tcl_NewObj();
  Tcl_ListObjAppendElement(0, pResult, Tcl_NewIntObj(rc));
  Tcl_ListObjAppendElement(0, pResult, Tcl_NewIntObj(N));
  Tcl_SetObjResult(interp, pResult);
  return TCL_OK;
}


/*
** Register commands with the TCL interpreter.
*/
int Sqlitetest_malloc_Init(Tcl_Interp *interp){
  static struct {
     char *zName;
................................................................................
     { "sqlite3_memory_highwater",   test_memory_highwater         },
     { "sqlite3_memdebug_backtrace", test_memdebug_backtrace       },
     { "sqlite3_memdebug_dump",      test_memdebug_dump            },
     { "sqlite3_memdebug_fail",      test_memdebug_fail            },
     { "sqlite3_memdebug_pending",   test_memdebug_pending         },
     { "sqlite3_memdebug_settitle",  test_memdebug_settitle        },
     { "sqlite3_memdebug_malloc_count", test_memdebug_malloc_count },
     { "sqlite3_memdebug_log",       test_memdebug_log             },
     { "sqlite3_config_scratch",     test_config_scratch           },
     { "sqlite3_config_pagecache",   test_config_pagecache         },
  };
  int i;
  for(i=0; i<sizeof(aObjCmd)/sizeof(aObjCmd[0]); i++){
    Tcl_CreateObjCommand(interp, aObjCmd[i].zName, aObjCmd[i].xProc, 0, 0);
  }
  return TCL_OK;
}