Re: [SMARTY] large result sets
| From: | Mark Rogers | Date: | Thu, 05 Aug 2004 10:53:50 +0000 |
| Subject: | Re: [SMARTY] large result sets | ||
| References: | 1 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-11665@lists.php.net to get a copy of this message | ||
> > correct. but i think there is a caveat in php4 with foreach. the
> > internal array pointer (http://php.net/current) is a property of the
> > assigned array. if you do foreach($array as $item), the internal
> > array-pointer gets reset. this is considered a change of the array and
> > the whole thing gets copied.
> >
> > [...]
>
> This is correct. See
> http://www.php.net/manual/en/control-structures.foreach.php for
> details.
This makes me even less sure I really know what is going on!
According to the foreach docs, foreach works on a copy, therefore it should
make no difference whether or not the array is passed to Smarty as a copy or
by reference, because either way the foreach will create a "new" copy which
it will change.
However, in addition foreach also updates the internal array-pointer, as
Messju points out, so *if* this is considered a change of the array then
we'll now have three copies of essentially the same array.
However (again), my (hazy) recollection is that the array copy will itself
just be a new set of array indexes pointing to references the original data,
unless/until that data changes. So the overall memory usage of this whole
process, assuming a large array, should be little over that used for the
array itself.
This should be semi-trivial to test - create a large array, look at the
memory used, then perform the copy/foreach steps and see how it changes. If
I get chance I might play with this some more, but right now I shouldn't
even really be writing this, I have too much else I should be doing.
--
Mark Rogers,
More Solutions Ltd