About the management of arrays and memory in PHP

Source: Internet
Author: User
About the management of arrays and memory in PHP
According to the manual, php except object, other types of variables in the assignment, parameter passing, return value is a copy of it
But look at the following test, do not know because the test method is a problem, or if it is not used & by reference, or share the same part of memory, but after changing its elements to actually generate a copy out?




------Solution--------------------
It's not clear what your goal is.
m = 0;
$m = Memory_get_usage ();
$t = array (' id ' = = 1, ' name ' = ' None ');
Echo ' $t occupancy: ', Memory_get_usage ()-$m, Php_eol;
$data = Array ();
Echo ' Empty $data occupy: ', Memory_get_usage ()-$m, Php_eol;
$m = Memory_get_usage ();
for ($i =0; $i <1000; $i + +) {
$data [] = null;
}
echo ' 1000 empty elements $data occupied: ', Memory_get_usage ()-$m, Php_eol;
$data = Array ();
$m = Memory_get_usage ();
for ($i =0; $i <1000; $i + +) {
$data [] = $t;
}
Echo ' 1000 $t elements of $data occupy: ', Memory_get_usage ()-$m, Php_eol;
$data = Array ();
$m = Memory_get_usage ();
for ($i =0; $i <1000; $i + +) {
$data [] = array (' id ' = = 1, ' name ' = ' None ');
}
$data occupancy of ECHO ' 1000 entity elements: ', Memory_get_usage ()-$m, Php_eol;
$t Occupation: 360
Empty $data Occupation: 496
$data occupancy of 1000 empty elements: 84200
$data occupancy of 1000 $t elements: 52104
$data occupancy of 1000 entity elements: 356136

It might be clearer.
------Solution--------------------
Reference:
Of course, that is the surface phenomenon, I want to know how to manage the memory of PHP, there is no official information what, or can only see the source of PHP?


Hash table
------Solution--------------------
PHP variables are copied at the time of writing
Look at this article: http://www.laruence.com/2008/09/19/520.html
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.