Welcome Guest, Not a member yet? Register   Sign In
Load library question
#1

[eluser]Sonolin[/eluser]
If multiple have a load->library calls (or load->database calls), would the library actually be loaded multiple times or only once? The reason I ask, is that for custom libraries, I usually load the database and libraries I need inside the custom library while these are sometimes already loaded - and I do not want any unneeded process time/odd things happening from loading things multiple times.

If the libraries are actually loaded multiple times, is there an easy way to check if the library is loaded or not? I'm assuming I can do something like this:

Code:
if (!isset($this->db)) {
$this->load->database();
}

(Not sure exactly if isset works on objects)
#2

[eluser]Dam1an[/eluser]
If you look in the Loader library, in the function _ci_load_class, you'll see that it checks if that class has already been loaded, and will only load it again if its being assigned to a new variable.

Interestingly enough, if you load the same class multiple times, the memory usage does go up thought

With classes such as the database, I would suggest autoloading them
#3

[eluser]Unknown[/eluser]
True, the memory usage does go up, so if I for example do just this:

Code:
$this->load->library('session');

or

Code:
$this->load->library('session');
$this->load->library('session');
$this->load->library('session');
$this->load->library('session');
// in a row

the amount of memory will be increased!
I guess it is a BUG?, so someone should report it!

Anyway, my sloution for libraries is:

Code:
// solution: not to load library twice, check if is loaded
if(!$this->load->is_loaded('session')
{
     $this->load->library('session');
}

And it works more then fine




Theme © iAndrew 2016 - Forum software by © MyBB