Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:59595 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 66146 invoked from network); 10 Apr 2012 02:03:35 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 10 Apr 2012 02:03:35 -0000 Authentication-Results: pb1.pair.com smtp.mail=jared.williams1@ntlworld.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=jared.williams1@ntlworld.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain ntlworld.com designates 81.103.221.48 as permitted sender) X-PHP-List-Original-Sender: jared.williams1@ntlworld.com X-Host-Fingerprint: 81.103.221.48 mtaout02-winn.ispmail.ntl.com Solaris 10 (beta) Received: from [81.103.221.48] ([81.103.221.48:30762] helo=mtaout02-winn.ispmail.ntl.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 47/3C-34074-6F4938F4 for ; Mon, 09 Apr 2012 22:03:35 -0400 Received: from aamtaout02-winn.ispmail.ntl.com ([81.103.221.35]) by mtaout02-winn.ispmail.ntl.com (InterMail vM.7.08.04.00 201-2186-134-20080326) with ESMTP id <20120410020331.JNEF23305.mtaout02-winn.ispmail.ntl.com@aamtaout02-winn.ispmail.ntl.com>; Tue, 10 Apr 2012 03:03:31 +0100 Received: from p2 ([82.3.19.10]) by aamtaout02-winn.ispmail.ntl.com (InterMail vG.3.00.04.00 201-2196-133-20080908) with ESMTP id <20120410020331.IPPA3795.aamtaout02-winn.ispmail.ntl.com@p2>; Tue, 10 Apr 2012 03:03:31 +0100 To: "'Ben Schmidt'" , Date: Tue, 10 Apr 2012 03:03:35 +0100 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Office Outlook, Build 11.0.5510 In-Reply-To: <4F838E2E.4040206@yahoo.com.au> Thread-Index: Ac0WujYKiOFv8f/GSmWZKPECOY+IbAAAs3kg X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.4325 Message-ID: <20120410020331.IPPA3795.aamtaout02-winn.ispmail.ntl.com@p2> X-Cloudmark-Analysis: v=1.1 cv=JvdXmxIgLJv2/GthKqHpGJEEHukvLcvELVXUanXFreg= c=1 sm=0 a=SZcSaUcd99QA:10 a=uObrxnre4hsA:10 a=oHf_AeXmDeQA:10 a=kj9zAlcOel0A:10 a=LX9nTfyjAAAA:8 a=67BIL_jfAAAA:8 a=sybU3C1Tap_Q0PHIXIUA:9 a=8LV-l1EVytm6rb1z6YMA:7 a=CjuIK1q_8ugA:10 a=HpAAvcLHHh0Zw7uRqdWCyQ==:117 Subject: RE: [PHP-DEV] Traits and memory size From: jared.williams1@ntlworld.com ("Jared Williams") References: <4F838E2E.4040206@yahoo.com.au> > -----Original Message----- > From: Ben Schmidt [mailto:mail_ben_schmidt@yahoo.com.au] > Sent: 10 April 2012 02:35 > To: internals@lists.php.net > Subject: [PHP-DEV] Traits and memory size > > Hi! > > Just a quick question about traits. > > During the flattening process, is a copy made of the trait > code (or bytecode or whatever)? > > So, if I have > > trait A { > // a bunch of methods > } > class B { > use A; > } > class C { > use A; > } > class D { > use A; > } > > will I have four copies of A because it has been copied into > all of the classes, and thus this aspect of my code will take > up four times as much memory than if I did: > > class A { > // a bunch of methods > } > class B extends A { > } > class C extends A { > } > class D extends A { > } > > Or is the code shared so the memory use will be roughly the same? > > I realise the use cases for traits and inheritance are > different, and often the situation will dictate the design, > but sometimes you have these two options so have to make a > design decision, and it would be nice to know the impact on > memory use/code size. > > Hope this is a simple question and won't take too much time > for anyone to answer! > > Thanks! > > Ben. > I don't know the answer to your question. But the decision to use traits or inheritance should be pretty obvious, and the amount of memory either way uses should be irrelevant. If either choice appears to be allocating too much, then it's the Zend Engine itself that should be looked at, and not rewritting PHP code. Jared