For example:
a(wordwrap(str_repeat('abcdef', 500000), 160, "
", true));
function a($v){
$v[1] = 'x';
$v = b($v);
return $v;
}
function b($v){
$v[2] = 'x';
$v = c($v);
return $v;
}
function c($v){
$v[3] = 'x';
d($v);
}
function d($v){
$v[4] = 'x';
print $v;
}
This uses ~23 MB. I think because PHP is creating a copy of that text on each modification. If I just print the text once it uses 12 MB.
Can I somehow free the memory for the original variable before functions are called? Like
unset($v);
$v = c($v);
Obviously this won't work because $v
is destroyed before it gets passed to c()
lol. But I'd like to somehow let c()
modify the same text. Like using references. (I tried references but they actually increase memory usage, probably because PHP makes more copies)