arrays and resources
Moderator: General Moderators
- hob_goblin
- Forum Regular
- Posts: 978
- Joined: Sun Apr 28, 2002 9:53 pm
- Contact:
arrays and resources
now that I think about it, everytime I run a script there are alot of arrays being passed..
$_GET
$_POST
$_COOKIE
and i can also still use
$HTTP_GET_VARS
$HTTP_POST_VARS
$HTTP_COOKIE_VARS
im just wondering, are these arrays made everytime the script is accessed?
would I get anything worthwhile using unset() to clear up some useless information at the begining of larger scripts?
$_GET
$_POST
$_COOKIE
and i can also still use
$HTTP_GET_VARS
$HTTP_POST_VARS
$HTTP_COOKIE_VARS
im just wondering, are these arrays made everytime the script is accessed?
would I get anything worthwhile using unset() to clear up some useless information at the begining of larger scripts?
- RandomEngy
- Forum Contributor
- Posts: 173
- Joined: Wed Jun 26, 2002 3:24 pm
- Contact:
- hob_goblin
- Forum Regular
- Posts: 978
- Joined: Sun Apr 28, 2002 9:53 pm
- Contact:
- RandomEngy
- Forum Contributor
- Posts: 173
- Joined: Wed Jun 26, 2002 3:24 pm
- Contact:
Ahh I see what you mean. Still, even if they are separate arrays, I don't see much gain to be had over it. Wouldn't it just go: PHP gets the information and puts it in two identical arrays, the script runs to create the page, and then both arrays are destroyed. So you'd be gaining a little bit of memory for the duration the script runs, but I don't think it's worth it.
And correct me if I'm wrong about the arrays getting deleted after the script finishes.
And correct me if I'm wrong about the arrays getting deleted after the script finishes.
You know, I'm willing to bet (or in other words, I'm making a kinda educated guess) that $HTTP_POST_VARS and $_POST are the same only in name and reference the same bit of memory space in the system.
So $HTTP_POST_VARS[joe_sixpack] and $_POST[joe_sixpack] are actually the same bit of memory space as opposed to one being a copy (or duplicate) of another. And of course, the frienly folks at PHP are allowing the continued, though deprecated, use of $HTTP_POST_VARS for slow tossers like me that can't get a big project done in under a year
Good thing I'm not getting paid for this one eh?
Besides, I can't see these guys justifying the creation of duplicate arrays. Most people are either going to use one or the other.
What do you think? Anybody feel like testing this? I'm compiling in shared memory support at this time so I'm out.
Later on,
BDKR (TRC)
So $HTTP_POST_VARS[joe_sixpack] and $_POST[joe_sixpack] are actually the same bit of memory space as opposed to one being a copy (or duplicate) of another. And of course, the frienly folks at PHP are allowing the continued, though deprecated, use of $HTTP_POST_VARS for slow tossers like me that can't get a big project done in under a year
Besides, I can't see these guys justifying the creation of duplicate arrays. Most people are either going to use one or the other.
What do you think? Anybody feel like testing this? I'm compiling in shared memory support at this time so I'm out.
Later on,
BDKR (TRC)
- hob_goblin
- Forum Regular
- Posts: 978
- Joined: Sun Apr 28, 2002 9:53 pm
- Contact:
Referencing is a clutch concept to understand. If you have:
and you call it like this:
you're creating a copy of your array, which is slow and takes up a lot of memory. The changes made to the array will also not be saved, only used inside the function doSomething. However, if you declare:
and:
you have only passed a reference to the contents of myBigArray, which is much smaller and faster. Keep in mind, now any changes to $bigArray will be reflected in $myBigArray, as they are two names for the same thing.
Reference: http://www.php.net/manual/en/language.references.php
Code: Select all
function doSomething($bigArray) {//do something}Code: Select all
doSomething($myBigArray);Code: Select all
function doSomething(&$bigArray) {//do something}Code: Select all
doSomething(&$myBigArray)Reference: http://www.php.net/manual/en/language.references.php
Last edited by llimllib on Fri Jul 05, 2002 3:15 pm, edited 1 time in total.