cvs: ZendEngine2 / zend_alloc.c

From: Date: Fri, 23 Mar 2007 07:59:54 +0000
Subject: cvs: ZendEngine2 / zend_alloc.c
Groups: php.zend-engine.cvs 
Request: Send a blank email to php-zend-engine-cvs+get-5699@lists.php.net to get a copy of this message
dmitry Fri Mar 23 07:59:54 2007 UTC Modified files: /ZendEngine2 zend_alloc.c Log: Fixed bug #40883 (mysql_query() is allocating memory incorrectly). (Tony) http://cvs.php.net/viewvc.cgi/ZendEngine2/zend_alloc.c?r1=1.197&r2=1.198&diff_format=u Index: ZendEngine2/zend_alloc.c diff -u ZendEngine2/zend_alloc.c:1.197 ZendEngine2/zend_alloc.c:1.198 --- ZendEngine2/zend_alloc.c:1.197 Tue Mar 20 06:47:12 2007 +++ ZendEngine2/zend_alloc.c Fri Mar 23 07:59:54 2007 @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_alloc.c,v 1.197 2007/03/20 06:47:12 dmitry Exp $ */ +/* $Id: zend_alloc.c,v 1.198 2007/03/23 07:59:54 dmitry Exp $ */ #include "zend.h" #include "zend_alloc.h" @@ -1966,6 +1966,50 @@ return p; } +#if ZEND_MM_CACHE + if (ZEND_MM_SMALL_SIZE(true_size)) { + size_t index = ZEND_MM_BUCKET_INDEX(true_size); + + if (heap->cache[index] != NULL) { + zend_mm_free_block *best_fit; + zend_mm_free_block **cache; + +#if ZEND_MM_CACHE_STAT + heap->cache_stat[index].count--; + heap->cache_stat[index].hit++; +#endif + best_fit = heap->cache[index]; + heap->cache[index] = best_fit->prev_free_block; + ZEND_MM_CHECK_MAGIC(best_fit, MEM_BLOCK_CACHED); + ZEND_MM_SET_DEBUG_INFO(best_fit, size, 1, 0); + + ptr = ZEND_MM_DATA_OF(best_fit); + +#if ZEND_DEBUG || ZEND_MM_HEAP_PROTECTION + memcpy(ptr, p, mm_block->debug.size); +#else + memcpy(ptr, p, orig_size - ZEND_MM_ALIGNED_HEADER_SIZE); +#endif + + heap->cached -= true_size - orig_size; + + index = ZEND_MM_BUCKET_INDEX(orig_size); + cache = &heap->cache[index]; + + ((zend_mm_free_block*)mm_block)->prev_free_block = *cache; + *cache = (zend_mm_free_block*)mm_block; + ZEND_MM_SET_MAGIC(mm_block, MEM_BLOCK_CACHED); +#if ZEND_MM_CACHE_STAT + if (++heap->cache_stat[index].count > heap->cache_stat[index].max_count) { + heap->cache_stat[index].max_count = heap->cache_stat[index].count; + } +#endif + + return ptr; + } + } +#endif + next_block = ZEND_MM_BLOCK_AT(mm_block, orig_size); if (ZEND_MM_IS_FREE_BLOCK(next_block)) {

« previous php.zend-engine.cvs (#5699) next »