xref: /sqlite-3.40.0/src/mem0.c (revision c81c11f6)
1*d1370b6dSdrh /*
2*d1370b6dSdrh ** 2008 October 28
3*d1370b6dSdrh **
4*d1370b6dSdrh ** The author disclaims copyright to this source code.  In place of
5*d1370b6dSdrh ** a legal notice, here is a blessing:
6*d1370b6dSdrh **
7*d1370b6dSdrh **    May you do good and not evil.
8*d1370b6dSdrh **    May you find forgiveness for yourself and forgive others.
9*d1370b6dSdrh **    May you share freely, never taking more than you give.
10*d1370b6dSdrh **
11*d1370b6dSdrh *************************************************************************
12*d1370b6dSdrh **
13*d1370b6dSdrh ** This file contains a no-op memory allocation drivers for use when
14*d1370b6dSdrh ** SQLITE_ZERO_MALLOC is defined.  The allocation drivers implemented
15*d1370b6dSdrh ** here always fail.  SQLite will not operate with these drivers.  These
16*d1370b6dSdrh ** are merely placeholders.  Real drivers must be substituted using
17*d1370b6dSdrh ** sqlite3_config() before SQLite will operate.
18*d1370b6dSdrh */
19*d1370b6dSdrh #include "sqliteInt.h"
20*d1370b6dSdrh 
21*d1370b6dSdrh /*
22*d1370b6dSdrh ** This version of the memory allocator is the default.  It is
23*d1370b6dSdrh ** used when no other memory allocator is specified using compile-time
24*d1370b6dSdrh ** macros.
25*d1370b6dSdrh */
26*d1370b6dSdrh #ifdef SQLITE_ZERO_MALLOC
27*d1370b6dSdrh 
28*d1370b6dSdrh /*
29*d1370b6dSdrh ** No-op versions of all memory allocation routines
30*d1370b6dSdrh */
sqlite3MemMalloc(int nByte)31*d1370b6dSdrh static void *sqlite3MemMalloc(int nByte){ return 0; }
sqlite3MemFree(void * pPrior)32*d1370b6dSdrh static void sqlite3MemFree(void *pPrior){ return; }
sqlite3MemRealloc(void * pPrior,int nByte)33*d1370b6dSdrh static void *sqlite3MemRealloc(void *pPrior, int nByte){ return 0; }
sqlite3MemSize(void * pPrior)34*d1370b6dSdrh static int sqlite3MemSize(void *pPrior){ return 0; }
sqlite3MemRoundup(int n)35*d1370b6dSdrh static int sqlite3MemRoundup(int n){ return n; }
sqlite3MemInit(void * NotUsed)36*d1370b6dSdrh static int sqlite3MemInit(void *NotUsed){ return SQLITE_OK; }
sqlite3MemShutdown(void * NotUsed)37*d1370b6dSdrh static void sqlite3MemShutdown(void *NotUsed){ return; }
38*d1370b6dSdrh 
39*d1370b6dSdrh /*
40*d1370b6dSdrh ** This routine is the only routine in this file with external linkage.
41*d1370b6dSdrh **
42*d1370b6dSdrh ** Populate the low-level memory allocation function pointers in
43*d1370b6dSdrh ** sqlite3GlobalConfig.m with pointers to the routines in this file.
44*d1370b6dSdrh */
sqlite3MemSetDefault(void)45*d1370b6dSdrh void sqlite3MemSetDefault(void){
46*d1370b6dSdrh   static const sqlite3_mem_methods defaultMethods = {
47*d1370b6dSdrh      sqlite3MemMalloc,
48*d1370b6dSdrh      sqlite3MemFree,
49*d1370b6dSdrh      sqlite3MemRealloc,
50*d1370b6dSdrh      sqlite3MemSize,
51*d1370b6dSdrh      sqlite3MemRoundup,
52*d1370b6dSdrh      sqlite3MemInit,
53*d1370b6dSdrh      sqlite3MemShutdown,
54*d1370b6dSdrh      0
55*d1370b6dSdrh   };
56*d1370b6dSdrh   sqlite3_config(SQLITE_CONFIG_MALLOC, &defaultMethods);
57*d1370b6dSdrh }
58*d1370b6dSdrh 
59*d1370b6dSdrh #endif /* SQLITE_ZERO_MALLOC */
60