note 74950 added to language.references
| From: | trucex at gmail dot com | Date: | Sat, 05 May 2007 20:49:16 +0000 |
| Subject: | note 74950 added to language.references | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-126227@lists.php.net to get a copy of this message | ||
In response to Xor and Slava:
I recommend you read up a bit more on the way PHP handles memory management. Take the following code
for example:
<?php
$data = $_POST['lotsofdata'];
$data2 = $data;
$data3 = $data;
$data4 = $data;
$data5 = $data;
?>
Assuming we post 10MB of data to this PHP file, what will PHP do with the memory?
PHP uses a table of sorts that maps variable names to the data that variable refers to in memory.
The $_POST superglobal will actually be the first instance of that data in the execution, so it will
be the first variable referenced to that data in the memory. It will consume 10MB. Each $data var
will simply point to the same data in memory. Until you change that data PHP will NOT duplicate it.
Passing a variable by value does just what I did with each $data var. There is no significant
overhead to assigning a new name to the same data. It is only when you modify the data passed to the
function that it must allocate memory for the data. Passing a variable by reference will do
essentially the same thing when you pass the data to the function, only modifying it will modify the
data that is in the memory already versus copying it to a new location in memory.
If for learning purposes you choose to disregard the obvious pointlessness in benchmarking the
difference between these two methods of passing arguments, you will need to modify the data when it
is passed to the function in order to obtain more accurate results.
----
Server IP: 64.71.164.2
Probable Submitter: 68.84.197.115
----
Manual Page -- http://www.php.net/manual/en/language.references.php
Edit -- https://master.php.net/note/edit/74950
Del: integrated -- https://master.php.net/note/delete/74950/integrated
Del: useless -- https://master.php.net/note/delete/74950/useless
Del: bad code -- https://master.php.net/note/delete/74950/bad+code
Del: spam -- https://master.php.net/note/delete/74950/spam
Del: non-english -- https://master.php.net/note/delete/74950/non-english
Del: in docs -- https://master.php.net/note/delete/74950/in+docs
Del: other reasons-- https://master.php.net/note/delete/74950
Reject -- https://master.php.net/note/reject/74950
Search -- https://master.php.net/manage/user-notes.php