Created
July 17, 2012 14:59
-
-
Save ichikaway/3129900 to your computer and use it in GitHub Desktop.
check copy on write of PHP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$GLOBALS['memstart'] = memory_get_usage(); | |
function mem() { | |
$m2 = memory_get_usage(); | |
echo $m2 - $GLOBALS['memstart'] ."\n"; | |
} | |
class Foo { | |
public function bar($x = null){ | |
echo "---------start Foo->bar() ----------\n"; | |
$c = $x; | |
mem(); | |
$c[1] = 21; | |
mem(); | |
} | |
} | |
function func($x=null) { | |
echo "---------start foo func----------\n"; | |
$c = $x; | |
mem(); | |
$c[1] = 21; | |
mem(); | |
} | |
$a = range(1,100); | |
$b = $a; | |
#$b[1] = 111; | |
func($a); | |
$foo = new Foo(); | |
$foo->bar($a); | |
echo "------- end this script -----------\n"; | |
mem(); | |
echo "\n\n"; | |
/* | |
RESULT | |
---------start foo func---------- | |
15176 | |
25200 | |
---------start Foo->bar() ---------- | |
15528 | |
25552 | |
------- end this script ----------- | |
15528 | |
*/ | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment