Jump to content


Photo

Resource type for storing object properties ?


  • Please log in to reply
2 replies to this topic

#1 micha

micha
  • New Members
  • Pip
  • Newbie
  • 4 posts
  • LocationGermany

Posted 21 April 2004 - 08:35 PM

Hi,

I wonder if a resource could be an option for storing object properties due to performance issues ?
In most of the class methods I have to access more than on member variable, so if I need access to e.g. 4 vars, zend_hash_find has to be called 4 times. For a resource which holds a structure with all member vars one call to ZEND_FETCH_RESOURCE would do it.

Well, does this make sense ?

micha


#2 daeken

daeken
  • Members
  • PipPip
  • Member
  • 22 posts
  • LocationChambersburg, PA

Posted 21 April 2004 - 09:14 PM

This _could_ be done... however, this would mean you couldn't let PHP access them directly, like an object. If it's just for internal use, go for it, otherwise I'd stick with normal objects.

Happy Hacking,
Lord Daeken M. BlackBlade
(Cody Brocious)
Black and white are all I see in my infancy.

#3 micha

micha
  • New Members
  • Pip
  • Newbie
  • 4 posts
  • LocationGermany

Posted 21 April 2004 - 09:47 PM

Hi daeken,

wow, thanks for your fast response.

This _could_ be done... however, this would mean you couldn't let PHP access them directly, like an object.


Yeah, this is ok since all vars are private (php4) and have appropriate get and set methods.
However, theoretically it should be possible to have both by storing the same pointer into the objects property hashtable and into the resources structure, shouldn't it ?

If it's just for internal use, go for it, otherwise I'd stick with normal objects.


Ok, great. They are all used internally and as a nice side effect I get *real* private vars and can be sure that the user doesn't change them.

Btw, do you know if fetching a resource is as fast as finding a hash entry...or even faster ?

Thx,
micha





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users