Artifact
6a55ebe57c46ca1a7d98da93aaa07f99f1059645 :
File
src/mem0.c
— part of check-in
[f6c045f649]
at
2009-11-10 01:30:53
on branch trunk
— Remove the obsolete "$Id:$" RCS identifier strings from the source code.
(user:
drh
size: 1929)
[more...]
0000: 2f 2a 0a 2a 2a 20 32 30 30 38 20 4f 63 74 6f 62 /*.** 2008 Octob
0010: 65 72 20 32 38 0a 2a 2a 0a 2a 2a 20 54 68 65 20 er 28.**.** The
0020: 61 75 74 68 6f 72 20 64 69 73 63 6c 61 69 6d 73 author disclaims
0030: 20 63 6f 70 79 72 69 67 68 74 20 74 6f 20 74 68 copyright to th
0040: 69 73 20 73 6f 75 72 63 65 20 63 6f 64 65 2e 20 is source code.
0050: 20 49 6e 20 70 6c 61 63 65 20 6f 66 0a 2a 2a 20 In place of.**
0060: 61 20 6c 65 67 61 6c 20 6e 6f 74 69 63 65 2c 20 a legal notice,
0070: 68 65 72 65 20 69 73 20 61 20 62 6c 65 73 73 69 here is a blessi
0080: 6e 67 3a 0a 2a 2a 0a 2a 2a 20 20 20 20 4d 61 79 ng:.**.** May
0090: 20 79 6f 75 20 64 6f 20 67 6f 6f 64 20 61 6e 64 you do good and
00a0: 20 6e 6f 74 20 65 76 69 6c 2e 0a 2a 2a 20 20 20 not evil..**
00b0: 20 4d 61 79 20 79 6f 75 20 66 69 6e 64 20 66 6f May you find fo
00c0: 72 67 69 76 65 6e 65 73 73 20 66 6f 72 20 79 6f rgiveness for yo
00d0: 75 72 73 65 6c 66 20 61 6e 64 20 66 6f 72 67 69 urself and forgi
00e0: 76 65 20 6f 74 68 65 72 73 2e 0a 2a 2a 20 20 20 ve others..**
00f0: 20 4d 61 79 20 79 6f 75 20 73 68 61 72 65 20 66 May you share f
0100: 72 65 65 6c 79 2c 20 6e 65 76 65 72 20 74 61 6b reely, never tak
0110: 69 6e 67 20 6d 6f 72 65 20 74 68 61 6e 20 79 6f ing more than yo
0120: 75 20 67 69 76 65 2e 0a 2a 2a 0a 2a 2a 2a 2a 2a u give..**.*****
0130: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
0140: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
0150: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
0160: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
0170: 2a 2a 2a 2a 0a 2a 2a 0a 2a 2a 20 54 68 69 73 20 ****.**.** This
0180: 66 69 6c 65 20 63 6f 6e 74 61 69 6e 73 20 61 20 file contains a
0190: 6e 6f 2d 6f 70 20 6d 65 6d 6f 72 79 20 61 6c 6c no-op memory all
01a0: 6f 63 61 74 69 6f 6e 20 64 72 69 76 65 72 73 20 ocation drivers
01b0: 66 6f 72 20 75 73 65 20 77 68 65 6e 0a 2a 2a 20 for use when.**
01c0: 53 51 4c 49 54 45 5f 5a 45 52 4f 5f 4d 41 4c 4c SQLITE_ZERO_MALL
01d0: 4f 43 20 69 73 20 64 65 66 69 6e 65 64 2e 20 20 OC is defined.
01e0: 54 68 65 20 61 6c 6c 6f 63 61 74 69 6f 6e 20 64 The allocation d
01f0: 72 69 76 65 72 73 20 69 6d 70 6c 65 6d 65 6e 74 rivers implement
0200: 65 64 0a 2a 2a 20 68 65 72 65 20 61 6c 77 61 79 ed.** here alway
0210: 73 20 66 61 69 6c 2e 20 20 53 51 4c 69 74 65 20 s fail. SQLite
0220: 77 69 6c 6c 20 6e 6f 74 20 6f 70 65 72 61 74 65 will not operate
0230: 20 77 69 74 68 20 74 68 65 73 65 20 64 72 69 76 with these driv
0240: 65 72 73 2e 20 20 54 68 65 73 65 0a 2a 2a 20 61 ers. These.** a
0250: 72 65 20 6d 65 72 65 6c 79 20 70 6c 61 63 65 68 re merely placeh
0260: 6f 6c 64 65 72 73 2e 20 20 52 65 61 6c 20 64 72 olders. Real dr
0270: 69 76 65 72 73 20 6d 75 73 74 20 62 65 20 73 75 ivers must be su
0280: 62 73 74 69 74 75 74 65 64 20 75 73 69 6e 67 0a bstituted using.
0290: 2a 2a 20 73 71 6c 69 74 65 33 5f 63 6f 6e 66 69 ** sqlite3_confi
02a0: 67 28 29 20 62 65 66 6f 72 65 20 53 51 4c 69 74 g() before SQLit
02b0: 65 20 77 69 6c 6c 20 6f 70 65 72 61 74 65 2e 0a e will operate..
02c0: 2a 2f 0a 23 69 6e 63 6c 75 64 65 20 22 73 71 6c */.#include "sql
02d0: 69 74 65 49 6e 74 2e 68 22 0a 0a 2f 2a 0a 2a 2a iteInt.h"../*.**
02e0: 20 54 68 69 73 20 76 65 72 73 69 6f 6e 20 6f 66 This version of
02f0: 20 74 68 65 20 6d 65 6d 6f 72 79 20 61 6c 6c 6f the memory allo
0300: 63 61 74 6f 72 20 69 73 20 74 68 65 20 64 65 66 cator is the def
0310: 61 75 6c 74 2e 20 20 49 74 20 69 73 0a 2a 2a 20 ault. It is.**
0320: 75 73 65 64 20 77 68 65 6e 20 6e 6f 20 6f 74 68 used when no oth
0330: 65 72 20 6d 65 6d 6f 72 79 20 61 6c 6c 6f 63 61 er memory alloca
0340: 74 6f 72 20 69 73 20 73 70 65 63 69 66 69 65 64 tor is specified
0350: 20 75 73 69 6e 67 20 63 6f 6d 70 69 6c 65 2d 74 using compile-t
0360: 69 6d 65 0a 2a 2a 20 6d 61 63 72 6f 73 2e 0a 2a ime.** macros..*
0370: 2f 0a 23 69 66 64 65 66 20 53 51 4c 49 54 45 5f /.#ifdef SQLITE_
0380: 5a 45 52 4f 5f 4d 41 4c 4c 4f 43 0a 0a 2f 2a 0a ZERO_MALLOC../*.
0390: 2a 2a 20 4e 6f 2d 6f 70 20 76 65 72 73 69 6f 6e ** No-op version
03a0: 73 20 6f 66 20 61 6c 6c 20 6d 65 6d 6f 72 79 20 s of all memory
03b0: 61 6c 6c 6f 63 61 74 69 6f 6e 20 72 6f 75 74 69 allocation routi
03c0: 6e 65 73 0a 2a 2f 0a 73 74 61 74 69 63 20 76 6f nes.*/.static vo
03d0: 69 64 20 2a 73 71 6c 69 74 65 33 4d 65 6d 4d 61 id *sqlite3MemMa
03e0: 6c 6c 6f 63 28 69 6e 74 20 6e 42 79 74 65 29 7b lloc(int nByte){
03f0: 20 72 65 74 75 72 6e 20 30 3b 20 7d 0a 73 74 61 return 0; }.sta
0400: 74 69 63 20 76 6f 69 64 20 73 71 6c 69 74 65 33 tic void sqlite3
0410: 4d 65 6d 46 72 65 65 28 76 6f 69 64 20 2a 70 50 MemFree(void *pP
0420: 72 69 6f 72 29 7b 20 72 65 74 75 72 6e 3b 20 7d rior){ return; }
0430: 0a 73 74 61 74 69 63 20 76 6f 69 64 20 2a 73 71 .static void *sq
0440: 6c 69 74 65 33 4d 65 6d 52 65 61 6c 6c 6f 63 28 lite3MemRealloc(
0450: 76 6f 69 64 20 2a 70 50 72 69 6f 72 2c 20 69 6e void *pPrior, in
0460: 74 20 6e 42 79 74 65 29 7b 20 72 65 74 75 72 6e t nByte){ return
0470: 20 30 3b 20 7d 0a 73 74 61 74 69 63 20 69 6e 74 0; }.static int
0480: 20 73 71 6c 69 74 65 33 4d 65 6d 53 69 7a 65 28 sqlite3MemSize(
0490: 76 6f 69 64 20 2a 70 50 72 69 6f 72 29 7b 20 72 void *pPrior){ r
04a0: 65 74 75 72 6e 20 30 3b 20 7d 0a 73 74 61 74 69 eturn 0; }.stati
04b0: 63 20 69 6e 74 20 73 71 6c 69 74 65 33 4d 65 6d c int sqlite3Mem
04c0: 52 6f 75 6e 64 75 70 28 69 6e 74 20 6e 29 7b 20 Roundup(int n){
04d0: 72 65 74 75 72 6e 20 6e 3b 20 7d 0a 73 74 61 74 return n; }.stat
04e0: 69 63 20 69 6e 74 20 73 71 6c 69 74 65 33 4d 65 ic int sqlite3Me
04f0: 6d 49 6e 69 74 28 76 6f 69 64 20 2a 4e 6f 74 55 mInit(void *NotU
0500: 73 65 64 29 7b 20 72 65 74 75 72 6e 20 53 51 4c sed){ return SQL
0510: 49 54 45 5f 4f 4b 3b 20 7d 0a 73 74 61 74 69 63 ITE_OK; }.static
0520: 20 76 6f 69 64 20 73 71 6c 69 74 65 33 4d 65 6d void sqlite3Mem
0530: 53 68 75 74 64 6f 77 6e 28 76 6f 69 64 20 2a 4e Shutdown(void *N
0540: 6f 74 55 73 65 64 29 7b 20 72 65 74 75 72 6e 3b otUsed){ return;
0550: 20 7d 0a 0a 2f 2a 0a 2a 2a 20 54 68 69 73 20 72 }../*.** This r
0560: 6f 75 74 69 6e 65 20 69 73 20 74 68 65 20 6f 6e outine is the on
0570: 6c 79 20 72 6f 75 74 69 6e 65 20 69 6e 20 74 68 ly routine in th
0580: 69 73 20 66 69 6c 65 20 77 69 74 68 20 65 78 74 is file with ext
0590: 65 72 6e 61 6c 20 6c 69 6e 6b 61 67 65 2e 0a 2a ernal linkage..*
05a0: 2a 0a 2a 2a 20 50 6f 70 75 6c 61 74 65 20 74 68 *.** Populate th
05b0: 65 20 6c 6f 77 2d 6c 65 76 65 6c 20 6d 65 6d 6f e low-level memo
05c0: 72 79 20 61 6c 6c 6f 63 61 74 69 6f 6e 20 66 75 ry allocation fu
05d0: 6e 63 74 69 6f 6e 20 70 6f 69 6e 74 65 72 73 20 nction pointers
05e0: 69 6e 0a 2a 2a 20 73 71 6c 69 74 65 33 47 6c 6f in.** sqlite3Glo
05f0: 62 61 6c 43 6f 6e 66 69 67 2e 6d 20 77 69 74 68 balConfig.m with
0600: 20 70 6f 69 6e 74 65 72 73 20 74 6f 20 74 68 65 pointers to the
0610: 20 72 6f 75 74 69 6e 65 73 20 69 6e 20 74 68 69 routines in thi
0620: 73 20 66 69 6c 65 2e 0a 2a 2f 0a 76 6f 69 64 20 s file..*/.void
0630: 73 71 6c 69 74 65 33 4d 65 6d 53 65 74 44 65 66 sqlite3MemSetDef
0640: 61 75 6c 74 28 76 6f 69 64 29 7b 0a 20 20 73 74 ault(void){. st
0650: 61 74 69 63 20 63 6f 6e 73 74 20 73 71 6c 69 74 atic const sqlit
0660: 65 33 5f 6d 65 6d 5f 6d 65 74 68 6f 64 73 20 64 e3_mem_methods d
0670: 65 66 61 75 6c 74 4d 65 74 68 6f 64 73 20 3d 20 efaultMethods =
0680: 7b 0a 20 20 20 20 20 73 71 6c 69 74 65 33 4d 65 {. sqlite3Me
0690: 6d 4d 61 6c 6c 6f 63 2c 0a 20 20 20 20 20 73 71 mMalloc,. sq
06a0: 6c 69 74 65 33 4d 65 6d 46 72 65 65 2c 0a 20 20 lite3MemFree,.
06b0: 20 20 20 73 71 6c 69 74 65 33 4d 65 6d 52 65 61 sqlite3MemRea
06c0: 6c 6c 6f 63 2c 0a 20 20 20 20 20 73 71 6c 69 74 lloc,. sqlit
06d0: 65 33 4d 65 6d 53 69 7a 65 2c 0a 20 20 20 20 20 e3MemSize,.
06e0: 73 71 6c 69 74 65 33 4d 65 6d 52 6f 75 6e 64 75 sqlite3MemRoundu
06f0: 70 2c 0a 20 20 20 20 20 73 71 6c 69 74 65 33 4d p,. sqlite3M
0700: 65 6d 49 6e 69 74 2c 0a 20 20 20 20 20 73 71 6c emInit,. sql
0710: 69 74 65 33 4d 65 6d 53 68 75 74 64 6f 77 6e 2c ite3MemShutdown,
0720: 0a 20 20 20 20 20 30 0a 20 20 7d 3b 0a 20 20 73 . 0. };. s
0730: 71 6c 69 74 65 33 5f 63 6f 6e 66 69 67 28 53 51 qlite3_config(SQ
0740: 4c 49 54 45 5f 43 4f 4e 46 49 47 5f 4d 41 4c 4c LITE_CONFIG_MALL
0750: 4f 43 2c 20 26 64 65 66 61 75 6c 74 4d 65 74 68 OC, &defaultMeth
0760: 6f 64 73 29 3b 0a 7d 0a 0a 23 65 6e 64 69 66 20 ods);.}..#endif
0770: 2f 2a 20 53 51 4c 49 54 45 5f 5a 45 52 4f 5f 4d /* SQLITE_ZERO_M
0780: 41 4c 4c 4f 43 20 2a 2f 0a ALLOC */.