aboutsummaryrefslogtreecommitdiff
path: root/src/malloc.c
diff options
context:
space:
mode:
authordrh <drh@noemail.net>2017-01-10 16:09:46 +0000
committerdrh <drh@noemail.net>2017-01-10 16:09:46 +0000
commit1d21bac8aa8e770cf164564b09380ccc1ea3a8a6 (patch)
treefda535bfe0b4f1f41d205a96e0f062be9995e698 /src/malloc.c
parentd9bcb32ebb4b94df6c241bc09080cd0832d3a01b (diff)
downloadsqlite-1d21bac8aa8e770cf164564b09380ccc1ea3a8a6.tar.gz
sqlite-1d21bac8aa8e770cf164564b09380ccc1ea3a8a6.zip
Avoid unnecessary calls to the xRoundup() method of the memory allocator when
the soft heap limit is not set. FossilOrigin-Name: 4209b89eab01814228a178963238e0dffffad2a4
Diffstat (limited to 'src/malloc.c')
-rw-r--r--src/malloc.c12
1 files changed, 5 insertions, 7 deletions
diff --git a/src/malloc.c b/src/malloc.c
index 84191c78a..053b57b47 100644
--- a/src/malloc.c
+++ b/src/malloc.c
@@ -217,14 +217,13 @@ static void sqlite3MallocAlarm(int nByte){
** Do a memory allocation with statistics and alarms. Assume the
** lock is already held.
*/
-static int mallocWithAlarm(int n, void **pp){
- int nFull;
+static void mallocWithAlarm(int n, void **pp){
void *p;
assert( sqlite3_mutex_held(mem0.mutex) );
- nFull = sqlite3GlobalConfig.m.xRoundup(n);
sqlite3StatusHighwater(SQLITE_STATUS_MALLOC_SIZE, n);
if( mem0.alarmThreshold>0 ){
sqlite3_int64 nUsed = sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED);
+ int nFull = sqlite3GlobalConfig.m.xRoundup(n);
if( nUsed >= mem0.alarmThreshold - nFull ){
mem0.nearlyFull = 1;
sqlite3MallocAlarm(nFull);
@@ -232,20 +231,19 @@ static int mallocWithAlarm(int n, void **pp){
mem0.nearlyFull = 0;
}
}
- p = sqlite3GlobalConfig.m.xMalloc(nFull);
+ p = sqlite3GlobalConfig.m.xMalloc(n);
#ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
if( p==0 && mem0.alarmThreshold>0 ){
sqlite3MallocAlarm(nFull);
- p = sqlite3GlobalConfig.m.xMalloc(nFull);
+ p = sqlite3GlobalConfig.m.xMalloc(n);
}
#endif
if( p ){
- nFull = sqlite3MallocSize(p);
+ int nFull = sqlite3MallocSize(p);
sqlite3StatusUp(SQLITE_STATUS_MEMORY_USED, nFull);
sqlite3StatusUp(SQLITE_STATUS_MALLOC_COUNT, 1);
}
*pp = p;
- return nFull;
}
/*