Welcome Guest, Not a member yet? Register   Sign In
Cost of CI instance?
#2

[eluser]Pascal Kriete[/eluser]
There is no notable performance hit.

Quote:Am I better off trying to put these helper functions in, say, a “common” controller (it’s the controllers that need access to these helper function) since the controller already has access to config, languages, models, etc. (these are usually already autoloaded)?

In principal it's a really simple system. We create an instance of the controller class that the url tells us to use. When you load something, we internally instantiate that library or model and attach a reference to the controller object.

Calling get_instance() simply returns a reference to that object. So after $CI =& get_instance(), $CI and the controller's $this are references to one and the same object.

If this is something you truly need on every request, creating a base controller would work. You could also create a library to hold your methods, and then call get_instance() once in the constructor. But I would only do that with groups of functions that share an overlying concept, not to dump random methods.

In this case organization will give you higher returns than looking for small performance benefits. Helpers exist for a reason, it's perfectly fine to have a handful.


Messages In This Thread
Cost of CI instance? - by El Forum - 11-05-2010, 06:52 PM
Cost of CI instance? - by El Forum - 11-05-2010, 07:06 PM
Cost of CI instance? - by El Forum - 11-05-2010, 07:12 PM



Theme © iAndrew 2016 - Forum software by © MyBB