有没有简单的方法来检查某个数组占用多少内存?
就像我有一些10k行数组,需要知道服务器在一些$arr
内记住它需要多少MB / KB
答案 0 :(得分:1)
答案 1 :(得分:1)
// how much memory are you using before building your array
$baseMemory = memory_get_usage(false);
// create your array
$a = array('A',1,'B',2);
// how much memory are you using now the array is built
$finalMemory = memory_get_usage(false);
// the difference is a pretty close approximation
$arrayMemory = $finalMemory - $baseMemory;