For Programmers: Free Programming Magazines  


Home > Archive > PHP Smarty Templates > August 2004 > Re: [SMARTY] large result sets









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: [SMARTY] large result sets
Mark Rogers

2004-08-05, 9:07 am

> > correct. but i think there is a caveat in php4 with foreach. the
>
> This is correct. See
> http://www.php.net/manual/en/contro...res.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
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com