andrey Wed May 10 11:53:13 2006 UTC Modified files: (Branch: PHP_5_2) /php-src/ext/mysqli mysqli.c mysqli_api.c Log: Don't allocate 2 chunks of memory when one can fit. Reduces memory fragmentation. There is one more place that fragments memory but it will complicate the ongoing Unicode upgrade of mysqli so leaving it away for now. http://cvs.php.net/viewcvs.cgi/php-src/ext/mysqli/mysqli.c?r1=1.72.2.16.2.2&r2=1.72.2.16.2.3&diff_format=u Index: php-src/ext/mysqli/mysqli.c diff -u php-src/ext/mysqli/mysqli.c:1.72.2.16.2.2 php-src/ext/mysqli/mysqli.c:1.72.2.16.2.3 --- php-src/ext/mysqli/mysqli.c:1.72.2.16.2.2 Tue May 9 23:58:46 2006 +++ php-src/ext/mysqli/mysqli.c Wed May 10 11:53:13 2006 @@ -15,7 +15,7 @@ | Author: Georg Richter <[EMAIL PROTECTED]> | +----------------------------------------------------------------------+ - $Id: mysqli.c,v 1.72.2.16.2.2 2006/05/09 23:58:46 helly Exp $ + $Id: mysqli.c,v 1.72.2.16.2.3 2006/05/10 11:53:13 andrey Exp $ */ #ifdef HAVE_CONFIG_H @@ -69,10 +69,6 @@ return; } - if (bbuf.is_null) { - efree(bbuf.is_null); - } - for (i=0; i < bbuf.var_cnt; i++) { /* free temporary bind buffer */ @@ -89,9 +85,18 @@ efree(bbuf.vars); } + /* + Don't free bbuf.is_null for FETCH_RESULT since we have allocated + is_null and buf in one block so we free only buf, which is the beginning + of the block. When FETCH_SIMPLE then buf wasn't allocated together with + buf and we have to free it. + */ if (type == FETCH_RESULT) { efree(bbuf.buf); + } else if (type == FETCH_SIMPLE){ + efree(bbuf.is_null); } + bbuf.var_cnt = 0; return; } http://cvs.php.net/viewcvs.cgi/php-src/ext/mysqli/mysqli_api.c?r1=1.118.2.22.2.1&r2=1.118.2.22.2.2&diff_format=u Index: php-src/ext/mysqli/mysqli_api.c diff -u php-src/ext/mysqli/mysqli_api.c:1.118.2.22.2.1 php-src/ext/mysqli/mysqli_api.c:1.118.2.22.2.2 --- php-src/ext/mysqli/mysqli_api.c:1.118.2.22.2.1 Mon May 8 15:06:51 2006 +++ php-src/ext/mysqli/mysqli_api.c Wed May 10 11:53:13 2006 @@ -15,7 +15,7 @@ | Author: Georg Richter <[EMAIL PROTECTED]> | +----------------------------------------------------------------------+ - $Id: mysqli_api.c,v 1.118.2.22.2.1 2006/05/08 15:06:51 andrey Exp $ + $Id: mysqli_api.c,v 1.118.2.22.2.2 2006/05/10 11:53:13 andrey Exp $ */ #ifdef HAVE_CONFIG_H @@ -250,12 +250,16 @@ } bind = (MYSQL_BIND *)ecalloc(var_cnt, sizeof(MYSQL_BIND)); - stmt->result.buf = (VAR_BUFFER *)ecalloc(var_cnt,sizeof(VAR_BUFFER)); - stmt->result.is_null = (char *)ecalloc(var_cnt, sizeof(char)); + { + int size; + char *p= emalloc(size= var_cnt * (sizeof(char) + sizeof(VAR_BUFFER))); + stmt->result.buf = (VAR_BUFFER *) p; + stmt->result.is_null = p + var_cnt * sizeof(VAR_BUFFER); + memset(p, 0, size); + } for (i=start; i < var_cnt + start ; i++) { ofs = i - start; - stmt->result.is_null[ofs] = 0; col_type = (stmt->stmt->fields) ? stmt->stmt->fields[ofs].type : MYSQL_TYPE_STRING; switch (col_type) { @@ -373,8 +377,8 @@ efree(stmt->result.buf[i].val); } } + /* Don't free stmt->result.is_null because is_null & buf are one block of memory */ efree(stmt->result.buf); - efree(stmt->result.is_null); RETVAL_FALSE; } else { stmt->result.var_cnt = var_cnt;
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php