Re: [PHP] RecursiveArrayIterator



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




Relevant Pages

  • Re: Array.Resize question
    ... resources, you still have to call Disposeby hand on each object. ... objects that are now thown out of the array released properly by the CLI?" ... Garbage Collection only occurs when the system is low on memory. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Array.Resize question
    ... other than low memory ), ... the word resources is used to refer to exactly the things ... array reallocation, and the *vast* majority of classes in the CLR do not ... The statement that Garbage Collection occurs only when memory is low is ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Array.Resize question
    ... Only if there are no other references to those objects, ... objects that are now thown out of the array released properly by the CLI?" ... Garbage Collection only occurs when the system is low on memory. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: setting variable for garbage collector
    ... >> If I have an array of Strings, how can I set it for garbage collection, ... > That will do the the trick for the array AND it's contents. ... I seem to be using an awful lot of memory. ...
    (comp.lang.java.help)
  • Re: [PHP] RecursiveArrayIterator
    ... well garbage collection will remove the copy of an array created by foreach, ... Foreach doesn't bother creating a copy of the array either. ... about arrays and if you're using iterators then you're also talking ...
    (php.general)