pre php ini_set memory_limit 512M echo memory_get_usage true 1024 1024

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<pre>
<?php
ini_set('memory_limit', '512M');
/*
echo memory_get_usage(true)/1024/1024, "МБ\n";
$var = array_fill(0, 100000, null);
echo memory_get_usage(true)/1024/1024, "МБ\n";
#result = 0.75МБ 13.5МБ
*/
/*
echo memory_get_usage(true)/1024/1024, "МБ\n";
for ($i = 0; $i < 100000; $i++)$var[$i] = null;
echo memory_get_usage(true)/1024/1024, "МБ\n";
# result = 0.75МБ 21МБ
*/
/*
$tmp = null;
echo memory_get_usage(true)/1024/1024, "МБ\n";
for ($i = 0; $i < 100000; $i++)$var[$i] = $tmp;
echo memory_get_usage(true)/1024/1024, "МБ\n";
# result = 0.75МБ 13.5МБ
*/
$var = array_fill(0, 100001, null);
$counter = 0;
foreach ($var as $v) {
if ($counter % 10000 == 0) echo memory_get_usage(true)/1024/1024, "МБ\n";
$counter++;
}
echo "---\n\n\n";
$counter = 0;
foreach ($var as &$v) {
if ($counter % 10000 == 0) echo memory_get_usage(true)/1024/1024, "МБ\n";
$counter++;
}
?>
</pre>