Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:66859 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 47028 invoked from network); 30 Mar 2013 07:46:01 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 30 Mar 2013 07:46:01 -0000 X-Host-Fingerprint: 86.14.252.140 cpc3-asfd3-2-0-cust139.1-2.cable.virginmedia.com Received: from [86.14.252.140] ([86.14.252.140:8022] helo=localhost.localdomain) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id BF/07-22694-83896515 for ; Sat, 30 Mar 2013 02:46:00 -0500 To: internals@lists.php.net,Frank Liepert Message-ID: <51569834.7090707@php.net> Date: Sat, 30 Mar 2013 07:45:56 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130311 Thunderbird/17.0.4 MIME-Version: 1.0 References: <000e01ce2c9d$85864560$9092d020$@Liepert@gmx.de> In-Reply-To: <000e01ce2c9d$85864560$9092d020$@Liepert@gmx.de> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Posted-By: 86.14.252.140 Subject: Re: Array of current instances count From: krakjoe@php.net (Joe Watkins) On 03/29/2013 04:50 PM, Frank Liepert wrote: > Hello Internals, > > I'm thinking about a new function returning an array of classes and their > individual number of instances. It would look pretty much like the result of > get_declared_classes(). > > > An Example: > > print_r (get_instantiated_classes()); > // Array () > > $foo = new StdClass; > > print_r (get_instantiated_classes()); > // Array ( [StdClass] => 1 ) > > $bar = new StdClass; > > print_r (get_instantiated_classes()); > // Array ( [StdClass] => 2 ) > > ... and so on > > > Such a function could be helpful when refactoring and/or optimizing an > application. Just think of implementing the flyweight pattern in parts of an > application, where it is applicable. You could check against precise > numbers, for example when you're expecting the number of instances to > decrease by a certain number. Besides microtime() and get_memory_usage(), it > could be another useful indicator. > > Since I'm neither familiar with C nor the Zend Engine, I cannot implement > the feature and do not know, if it is even possible. > > But first of all, I'm asking you for your opinions. > > > Frank > I think there is some merit to that ... https://gist.github.com/krakjoe/5275773 The question is, why no ZTS ? NJoy :) Joe