dpqg86714 2012-06-24 09:52
浏览 22
已采纳

php内存使用情况

It looks like in PHP it requires about 213 bytes to store one integer, is it true? Okay, please take a look on the next code:

$N = 10000;
echo memory_get_usage()."
";
$v = array();
for($i = 0; $i < $N; $i++) {
    $v[] = $i;
}
echo memory_get_usage()."
";
unset($v);
echo memory_get_usage()."
";

Output is next:

641784
2773768
642056

So, the difference is 2773768 - 641784 = 2131984 byte, or 213 byte per integer. why so much? 4 bytes is more than enough.

  • 写回答

1条回答 默认 最新

  • dtf76989 2012-06-24 10:37
    关注

    4 bytes is only enough if you simply store an integer value somewhere in memory, without making any allowance for the fact that it is a variable which needs a datatype identification, flags to indicate if there are any other references to that variable, the name of that variable, etc. all of which require additional memory.

    PHP stores the value in a zval* so there's all the additional bytes used to store the zval details in addition to the actual value.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么