Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:51313 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 69499 invoked from network); 19 Jan 2011 06:44:20 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 19 Jan 2011 06:44:20 -0000 Authentication-Results: pb1.pair.com smtp.mail=larry@garfieldtech.com; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=larry@garfieldtech.com; sender-id=unknown Received-SPF: error (pb1.pair.com: domain garfieldtech.com from 76.96.30.16 cause and error) X-PHP-List-Original-Sender: larry@garfieldtech.com X-Host-Fingerprint: 76.96.30.16 qmta01.emeryville.ca.mail.comcast.net Received: from [76.96.30.16] ([76.96.30.16:48333] helo=qmta01.emeryville.ca.mail.comcast.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 94/88-18515-248863D4 for ; Wed, 19 Jan 2011 01:44:19 -0500 Received: from omta05.emeryville.ca.mail.comcast.net ([76.96.30.43]) by qmta01.emeryville.ca.mail.comcast.net with comcast id xJXl1f0010vp7WLA1JkGR1; Wed, 19 Jan 2011 06:44:16 +0000 Received: from earth.ufp ([98.220.236.211]) by omta05.emeryville.ca.mail.comcast.net with comcast id xJkF1f0074aLjBW8RJkF3R; Wed, 19 Jan 2011 06:44:16 +0000 Received: from localhost (localhost [127.0.0.1]) by earth.ufp (Postfix) with ESMTP id 08750D7A66 for ; Wed, 19 Jan 2011 00:44:15 -0600 (CST) Received: from earth.ufp ([127.0.0.1]) by localhost (earth.ufp [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id nV2wxx4MJzxT for ; Wed, 19 Jan 2011 00:44:14 -0600 (CST) Received: from linux-nkec.site (unknown [192.168.42.1]) by earth.ufp (Postfix) with ESMTPSA id E3921D7A59 for ; Wed, 19 Jan 2011 00:44:14 -0600 (CST) To: "internals@lists.php.net" Date: Wed, 19 Jan 2011 00:45:31 -0600 User-Agent: KMail/1.13.5 (Linux/2.6.34.7-0.7-desktop; KDE/4.4.4; x86_64; ; ) MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Message-ID: <201101190045.31781.larry@garfieldtech.com> Subject: How deep is copy on write? From: larry@garfieldtech.com (Larry Garfield) Hi folks. I have a question about the PHP runtime that I hope is appropriate for this list. (If not, please thwap me gently; I bruise easily.) I know PHP does copy-on-write. However, how "deeply" does it copy when dealing with nested arrays? This is probably easiest to explain with an example... $a['foo']['bar']['baz'] = 1; $a['foo']['bar']['bob'] = 1; $a['foo']['bar']['narf'] = 1; $a['foo']['poink']['narf'] = 1; function test($b) { // Assume each of the following lines in isolation... // Does this copy just the one variable baz, or the full array? $b['foo']['bar']['baz'] = 2; // Does this copy $b, or just $b['foo']['poink']? $b['foo']['poink']['stuff'] = 3; return $b; } // I know this is wasteful; I'm trying to figure out just how wasteful. $a = test($a); test() in this case should take $b by reference, but I'm trying to determine how much of a difference it is. (In practice my use case has a vastly larger array, so any inefficiencies are multiplied.) --Larry Garfield