Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:46101 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 49259 invoked from network); 19 Nov 2009 12:42:38 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 19 Nov 2009 12:42:38 -0000 Authentication-Results: pb1.pair.com header.from=yoarvi@gmail.com; sender-id=pass; domainkeys=bad Authentication-Results: pb1.pair.com smtp.mail=yoarvi@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.216.178 as permitted sender) DomainKey-Status: bad X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 X-PHP-List-Original-Sender: yoarvi@gmail.com X-Host-Fingerprint: 209.85.216.178 mail-px0-f178.google.com Received: from [209.85.216.178] ([209.85.216.178:63698] helo=mail-px0-f178.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 46/78-01102-D3D350B4 for ; Thu, 19 Nov 2009 07:42:38 -0500 Received: by pxi8 with SMTP id 8so1757534pxi.27 for ; Thu, 19 Nov 2009 04:42:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:date:message-id:subject :from:to:content-type; bh=gklkwJ/5roSwzUsKvJOFdW01/A/rvuzccs2hjecqanA=; b=Yl+1deJaQRios0gSiDFLOiJXMovDIkI3U5BAmujmdBBULEfcNJsj/fSmLwCf3IvzgP XI0yJLh3VU5mf1iWbTBJvDt7h8iQsGZw1+ezQuC7t3XCWA9k4fT/cjG/saA/PnRhmmpy 0b3x8EJkFoQlkyNTcJjgQRbnwSc+Xi7+yxNrA= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:content-type; b=Ars8AmDY33+lZGhzxLwQpK9p1o/HNXyuWwlVqtRMsPGoacczCP+vxY2LVzLeeRfseM 6YobZ2Vzrfw318Mp5hDgaEA+KgkxEGidkclJaJOf7NgbhCFWYCv3KuFKrw55tPIT1i5q DNQOESFSpfR+SG+DX9pkuWyPIXDCUx/k0JctM= MIME-Version: 1.0 Received: by 10.143.21.29 with SMTP id y29mr1403378wfi.175.1258634555309; Thu, 19 Nov 2009 04:42:35 -0800 (PST) Date: Thu, 19 Nov 2009 18:12:35 +0530 Message-ID: To: internals@lists.php.net Content-Type: text/plain; charset=ISO-8859-1 Subject: Question about buffer size calculation in _php_stream_copy_to_mem_ex From: yoarvi@gmail.com (Arvind Srinivasan) I see the following in _php_stream_copy_to_mem_ex in main/streams/streams.c int step = CHUNK_SIZE; int min_room = CHUNK_SIZE / 4; (..stuff deleted..) /* avoid many reallocs by allocating a good sized chunk to begin with, if * we can. Note that the stream may be filtered, in which case the stat * result may be inaccurate, as the filter may inflate or deflate the * number of bytes that we can read. In order to avoid an upsize followed * by a downsize of the buffer, overestimate by the step size (which is * 2K). */ if (php_stream_stat(src, &ssbuf) == 0 && ssbuf.sb.st_size > 0) { max_len = ssbuf.sb.st_size + step; } else { max_len = step; } According to the comment the intention is to overestimate by 2K, but CHUNK_SIZE = 8192 and that leads quite a bit of over-allocation of memory. Is the following a better setting for max_len in the if block? max_len = (((ssbuf.sb.st_size + min_room)/step) + 1) * step; The following are sample values that show the current vs new size calculation. ssbuf.sb.st_size, max_len (current), max_len (new) ( 100, 8292, 8192) ( 1000, 9192, 8192) ( 5000, 13192, 8192) ( 7000, 15192, 16384) ( 13000, 21192, 16384) ( 22000, 30192, 24576) thanks, arvi