Yeah, I thought about using LimitIterator [1] to avoid the creation of temporary arrays but I wasn't sure about the performance of it (does it always seek?) or if it works with Traversables.

A custom "LimitIterator", without seeking, might of course work, or perhaps it's enough to just modify the code and use a SplFixedArray object to ensure constant memory usage, without relying on PHP's garbage collector to do the job.


[1] http://php.net/limititerator

/imv

On 1/4/10 3:19 PM, Kornel Lesiński wrote:
On 31-12-2009 at 15:23:20 Iván Montes <drsl...@pollinimini.net> wrote:

I've put together a very simple chunk iterator [1] which works with arrays, traversables and iterators. There is also an example tales modifier.

Perhaps it could even be added to the standard PHPTAL code base?

[1] http://gist.github.com/266759

Thank you.

That's a good start, but doesn't avoid creation of arrays yet. What I actually had in mind was pair of iterators (one for rows like you've created, another for each row) that doesn't create PHP array at any point, just passes calls to the innermost iterator. That would ensure constant memory usage (rather than 1/number_of_columns) on arbitrarily large iterations, which I think is the major reason to use iterators instead of (presumably faster) array_chunk(iterator_to_array()).


_______________________________________________
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal

Reply via email to