Overview
| SHA1 Hash: | 238e35a4411a5b2231576254dba39b802947d4f3 |
|---|---|
| Date: | 2012-01-18 12:46:47 |
| User: | drh |
| Comment: | Add the SQLITE_WITHOUT_MSIZE and SQLITE_WITHOUT_ZONEMALLOC macros in mem1.c to disable the use of _msize() on windows and the zone memory allocator on Apple products, respectively. |
Tags And Properties
- branch=trunk inherited from [704b122e53]
- sym-trunk inherited from [704b122e53]
Changes
Changes to src/mem1.c
11 ************************************************************************* 11 ************************************************************************* 12 ** 12 ** 13 ** This file contains low-level memory allocation drivers for when 13 ** This file contains low-level memory allocation drivers for when 14 ** SQLite will use the standard C-library malloc/realloc/free interface 14 ** SQLite will use the standard C-library malloc/realloc/free interface 15 ** to obtain the memory it needs. 15 ** to obtain the memory it needs. 16 ** 16 ** 17 ** This file contains implementations of the low-level memory allocation 17 ** This file contains implementations of the low-level memory allocation 18 ** routines specified in the sqlite3_mem_methods object. | 18 ** routines specified in the sqlite3_mem_methods object. The content of > 19 ** this file is only used if SQLITE_SYSTEM_MALLOC is defined. The > 20 ** SQLITE_SYSTEM_MALLOC macro is defined automatically if neither the > 21 ** SQLITE_MEMDEBUG nor the SQLITE_WIN32_MALLOC macros are defined. The > 22 ** default configuration is to use memory allocation routines in this > 23 ** file. > 24 ** > 25 ** C-preprocessor macro summary: > 26 ** > 27 ** HAVE_MALLOC_USABLE_SIZE The configure script sets this symbol if > 28 ** the malloc_usable_size() interface exists > 29 ** on the target platform. Or, this symbol > 30 ** can be set manually, if desired. > 31 ** If an equivalent interface exists by > 32 ** a different name, using a separate -D > 33 ** option to rename it. This symbol will > 34 ** be enabled automatically on windows > 35 ** systems, and malloc_usable_size() will > 36 ** be redefined to _msize(), unless the > 37 ** SQLITE_WITHOUT_MSIZE macro is defined. > 38 ** > 39 ** SQLITE_WITHOUT_ZONEMALLOC Some older macs lack support for the zone > 40 ** memory allocator. Set this symbol to enable > 41 ** building on older macs. > 42 ** > 43 ** SQLITE_WITHOUT_MSIZE Set this symbol to disable the use of > 44 ** _msize() on windows systems. This might > 45 ** be necessary when compiling for Delphi, > 46 ** for example. 19 */ 47 */ 20 #include "sqliteInt.h" 48 #include "sqliteInt.h" 21 49 22 /* 50 /* 23 ** This version of the memory allocator is the default. It is 51 ** This version of the memory allocator is the default. It is 24 ** used when no other memory allocator is specified using compile-time 52 ** used when no other memory allocator is specified using compile-time 25 ** macros. 53 ** macros. 26 */ 54 */ 27 #ifdef SQLITE_SYSTEM_MALLOC 55 #ifdef SQLITE_SYSTEM_MALLOC 28 56 29 /* 57 /* 30 ** Windows systems have malloc_usable_size() but it is called _msize() | 58 ** Windows systems have malloc_usable_size() but it is called _msize(). > 59 ** The use of _msize() is automatic, but can be disabled by compiling > 60 ** with -DSQLITE_WITHOUT_MSIZE 31 */ 61 */ 32 #if !defined(HAVE_MALLOC_USABLE_SIZE) && SQLITE_OS_WIN | 62 #if !defined(HAVE_MALLOC_USABLE_SIZE) && SQLITE_OS_WIN \ > 63 && !defined(SQLITE_WITHOUT_MSIZE) 33 # define HAVE_MALLOC_USABLE_SIZE 1 64 # define HAVE_MALLOC_USABLE_SIZE 1 34 # define malloc_usable_size _msize 65 # define malloc_usable_size _msize 35 #endif 66 #endif 36 67 37 #if defined(__APPLE__) | 68 #if defined(__APPLE__) && !defined(SQLITE_WITHOUT_ZONEMALLOC) 38 69 39 /* 70 /* 40 ** Use the zone allocator available on apple products | 71 ** Use the zone allocator available on apple products unless the > 72 ** SQLITE_WITHOUT_ZONEMALLOC symbol is defined. 41 */ 73 */ 42 #include <sys/sysctl.h> 74 #include <sys/sysctl.h> 43 #include <malloc/malloc.h> 75 #include <malloc/malloc.h> 44 #include <libkern/OSAtomic.h> 76 #include <libkern/OSAtomic.h> 45 static malloc_zone_t* _sqliteZone_; 77 static malloc_zone_t* _sqliteZone_; 46 #define SQLITE_MALLOC(x) malloc_zone_malloc(_sqliteZone_, (x)) 78 #define SQLITE_MALLOC(x) malloc_zone_malloc(_sqliteZone_, (x)) 47 #define SQLITE_FREE(x) malloc_zone_free(_sqliteZone_, (x)); 79 #define SQLITE_FREE(x) malloc_zone_free(_sqliteZone_, (x)); ................................................................................................................................................................................ 48 #define SQLITE_REALLOC(x,y) malloc_zone_realloc(_sqliteZone_, (x), (y)) 80 #define SQLITE_REALLOC(x,y) malloc_zone_realloc(_sqliteZone_, (x), (y)) 49 #define SQLITE_MALLOCSIZE(x) \ 81 #define SQLITE_MALLOCSIZE(x) \ 50 (_sqliteZone_ ? _sqliteZone_->size(_sqliteZone_,x) : malloc_size(x)) 82 (_sqliteZone_ ? _sqliteZone_->size(_sqliteZone_,x) : malloc_size(x)) 51 83 52 #else /* if not __APPLE__ */ 84 #else /* if not __APPLE__ */ 53 85 54 /* 86 /* 55 ** Use standard C library malloc and free on non-Apple systems. | 87 ** Use standard C library malloc and free on non-Apple systems. > 88 ** Also used by Apple systems if SQLITE_WITHOUT_ZONEMALLOC is defined. 56 */ 89 */ 57 #define SQLITE_MALLOC(x) malloc(x) 90 #define SQLITE_MALLOC(x) malloc(x) 58 #define SQLITE_FREE(x) free(x) 91 #define SQLITE_FREE(x) free(x) 59 #define SQLITE_REALLOC(x,y) realloc((x),(y)) 92 #define SQLITE_REALLOC(x,y) realloc((x),(y)) 60 93 61 #ifdef HAVE_MALLOC_USABLE_SIZE 94 #ifdef HAVE_MALLOC_USABLE_SIZE 62 #include <malloc.h> 95 #include <malloc.h> ................................................................................................................................................................................ 180 return ROUND8(n); 213 return ROUND8(n); 181 } 214 } 182 215 183 /* 216 /* 184 ** Initialize this module. 217 ** Initialize this module. 185 */ 218 */ 186 static int sqlite3MemInit(void *NotUsed){ 219 static int sqlite3MemInit(void *NotUsed){ 187 #if defined(__APPLE__) | 220 #if defined(__APPLE__) && !defined(SQLITE_WITHOUT_ZONEMALLOC) 188 int cpuCount; 221 int cpuCount; 189 size_t len; 222 size_t len; 190 if( _sqliteZone_ ){ 223 if( _sqliteZone_ ){ 191 return SQLITE_OK; 224 return SQLITE_OK; 192 } 225 } 193 len = sizeof(cpuCount); 226 len = sizeof(cpuCount); 194 /* One usually wants to use hw.acctivecpu for MT decisions, but not here */ 227 /* One usually wants to use hw.acctivecpu for MT decisions, but not here */