Re: RecursiveArrayIterator

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 7/23/07, Larry Garfield <larry@xxxxxxxxxxxxxxxx> wrote:
Isn't that what garbage collection is for?

well garbage collection will remove the copy of an array created by foreach,
but what Kevin
is saying is Iterators dont bother creating a copy of the array, which
overall results in memory
savings.

-nathan

On 7/23/07, Larry Garfield <larry@xxxxxxxxxxxxxxxx> wrote:

On Monday 23 July 2007, Kevin Waterson wrote:
> This one time, at band camp, Jim Lucas <lists@xxxxxxxxx> wrote:
> > I don't get it, why not do this?
> >
> > foreach ( $array AS $row ) {
> >     foreach ( $row AS $k => $v ) {
> >             if ( ! is_array($v) ) {
> >                     echo "{$k} -- {$v}<br/>\n";
> >             }
> >     }
> > }
> >
> >
> > Maybe I am missing the point...  ???
>
> Indeed, whilst your method is simplistic it leaves many copies of the
array
> dangling in memory. Every time you call foreach it creates a copy of the
> array internally. SPL iterators do things differently and know only one
> element at a time. More can be seen at
> http://phpro.org/tutorials/Introduction-to-SPL.html
>
> so the final solution was using a foreach, however, using a foreach on
an
> SPL iterator object implicitly calls the inner iterator giving us all
the
> SPL goodness in memory savings.

Isn't that what garbage collection is for?

--
Larry Garfield                  AIM: LOLG42
larry@xxxxxxxxxxxxxxxx          ICQ: 6817012

"If nature has made any one thing less susceptible than all others of
exclusive property, it is the action of the thinking power called an idea,
which an individual may exclusively possess as long as he keeps it to
himself; but the moment it is divulged, it forces itself into the
possession
of every one, and the receiver cannot dispossess himself of it."  --
Thomas
Jefferson

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux