Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:51314 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 71902 invoked from network); 19 Jan 2011 07:01:59 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 19 Jan 2011 07:01:59 -0000 Authentication-Results: pb1.pair.com header.from=mail_ben_schmidt@yahoo.com.au; sender-id=unknown; domainkeys=good Authentication-Results: pb1.pair.com smtp.mail=mail_ben_schmidt@yahoo.com.au; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain yahoo.com.au from 98.138.91.54 cause and error) DomainKey-Status: good X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 X-PHP-List-Original-Sender: mail_ben_schmidt@yahoo.com.au X-Host-Fingerprint: 98.138.91.54 nm6-vm0.bullet.mail.ne1.yahoo.com Received: from [98.138.91.54] ([98.138.91.54:43695] helo=nm6-vm0.bullet.mail.ne1.yahoo.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 41/E8-18515-66C863D4 for ; Wed, 19 Jan 2011 02:01:59 -0500 Received: from [98.138.90.57] by nm6.bullet.mail.ne1.yahoo.com with NNFMP; 19 Jan 2011 07:01:56 -0000 Received: from [98.138.89.244] by tm10.bullet.mail.ne1.yahoo.com with NNFMP; 19 Jan 2011 07:01:56 -0000 Received: from [127.0.0.1] by omp1058.mail.ne1.yahoo.com with NNFMP; 19 Jan 2011 07:01:56 -0000 X-Yahoo-Newman-Id: 530895.60579.bm@omp1058.mail.ne1.yahoo.com Received: (qmail 10755 invoked from network); 19 Jan 2011 07:01:56 -0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com.au; h=DKIM-Signature:Received:X-Yahoo-SMTP:X-YMail-OSG:X-Yahoo-Newman-Property:Message-ID:Date:From:User-Agent:MIME-Version:To:CC:Subject:References:In-Reply-To:Content-Type:Content-Transfer-Encoding; b=wIcb8kQ30f3qh0UCapynujpUqUPdeQTXQUjzR18qlybJkM9iXPpBk5ZD2OCqkfkk8twqY9NEHEGlvhDLcSPXzgLBi0RGzXf5hTB2LPrEz2JsjaE/Z0dIY+PRnTRFmylDiAHOf4KMSbfWz0C2jJ2+R4Z6/uSBTEuYXh/FSA1NBU4= ; DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com.au; s=s1024; t=1295420516; bh=5M7o9f4BWaPF/Ypp9mdBRwQ5MfySKJebEQr/PNEjF1c=; h=Received:X-Yahoo-SMTP:X-YMail-OSG:X-Yahoo-Newman-Property:Message-ID:Date:From:User-Agent:MIME-Version:To:CC:Subject:References:In-Reply-To:Content-Type:Content-Transfer-Encoding; b=1LbQm9f4jO3K7jouxBL6E1EW+6nAyznQVC7Nm39lsZbonVPWCPrTz0nZ3wSwNwq+k32bu7xd7QoYwYlxllHagniLuEjTzUOs09aQ9Me1xNgDXLHwQjOkqAjoapwMhE93/XByZVTSNQpnycV4YIVO/t+0L38PQja62mZx646kmpY= Received: from 194.20.70.115.static.exetel.com.au (mail_ben_schmidt@115.70.20.194 with plain) by smtp148.mail.mud.yahoo.com with SMTP; 18 Jan 2011 23:01:53 -0800 PST X-Yahoo-SMTP: enFMnPSswBAexaHyzgobwuUTrYOhZdJ0KRA2SjA- X-YMail-OSG: zs60GtIVM1nnyF1vGEtQsHlr.kJwECpgoDVf00I.6Foh8CC ImC9ujv4urDlCmr1Js4HxxXG.xIR84Zu67.Ac1yjAkxOzj4zlku48sN6.6kd KX7kYw5.Ibm0L6gVpSOl8ASHD69LkJ2A2F5TYaT9tim470q9LUuCyXu2HgXL iymKr.D760c_WETpvuOTpEEnabP0BeA0GjIPpcmuzaZsoZuAFjG83RP0vQz8 kUBU_O3b15f5OEMzuJKugyMLeSZYpjD7U4KVXgsiPwmAxxkU1MT9WIUzVC5e irIAYE05A4BgPadAPu4UnnakdY62NqbF7kqmw5sIDB5koOnBEhd84S61kjpn R3SpV0HOYSp5T4uzICCg4_KXBaQ-- X-Yahoo-Newman-Property: ymail-3 Message-ID: <4D368C58.2040903@yahoo.com.au> Date: Wed, 19 Jan 2011 18:01:44 +1100 User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-GB; rv:1.9.2.13) Gecko/20101207 Thunderbird/3.1.7 ThunderBrowse/3.3.4 MIME-Version: 1.0 To: Larry Garfield CC: "internals@lists.php.net" References: <201101190045.31781.larry@garfieldtech.com> In-Reply-To: <201101190045.31781.larry@garfieldtech.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] How deep is copy on write? From: mail_ben_schmidt@yahoo.com.au (Ben Schmidt) It does the whole of $b. It has to, because when you change 'baz', a reference in 'bar' needs to change to point to the newly copied 'baz', so 'bar' is written...and likewise 'foo' is written. Ben. On 19/01/11 5:45 PM, Larry Garfield wrote: > 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 >