Hi Sara,

Sara Golemon wrote:
On Tue, Jan 5, 2016 at 12:52 PM, Andrea Faulds <a...@ajf.me> wrote:
This is more of a side-note, but maybe it's worth bringing up. Since
token_get_all gives an array with subarrays of a regular structure, might it
be worthwhile returning an array of objects instead? It would probably
reduce memory usage (assuming they're objects of a Token class or something,
not StdClass), but I don't know if it's that useful.

Is the internal memory usage of (new stdClass) actually less than
(array())?  I know array changed a lot with PHP7, and that the kind of
array we're talking about here is a mixed (which would be the least
efficient), but I don't have the numbers to hand.

No, a StdClass would consume more memory than an array, because it has a hashtable plus object overhead.

But having a specific token class would much consume less, since there's no hashtable overhead for defined properties:

https://gist.github.com/nikic/5015323

I believe it's even better in PHP 7.

To your question, I'm cool either way.  Though if memory/efficiency is
a concern, returning an iterator would be even better, especially on
large files.  Though I think that's beyond the scope of this
particular RFC.

Memory probably doesn't matter, this was mostly a "what if" suggestion.


Maybe I should keep up my "1 RFC per day" run and suggest
TOKEN_ITERATOR as yet another flag....   Maybe not.  My inbox hurts.

I know first-hand what making too many RFCs can do to you, so I wouldn't recommend it.

Thanks! :)
--
Andrea Faulds
https://ajf.me/

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to