在PHP中获取对象在内存中的大小?

PhpPhp 2023-09-01 03:21:14 1101
摘要: 可以在为创建的类分配内存之前和之后调用memory_get_usage()函数。classMyBigClass{var$allocatedSize;var$allMyOtherStuff;}functionAllocateMyBigClass(){$before=memory_get_usage();...

在PHP中获取对象在内存中的大小?

可以在为创建的类分配内存之前和之后调用 memory_get_usage() 函数。

class MyBigClass {
   var $allocatedSize;
   var $allMyOtherStuff;
}
function AllocateMyBigClass() {
   $before = memory_get_usage();
   $ret = new MyBigClass;
   $after = memory_get_usage();
   $ret->allocatedSize = ($after - $before);
   return $ret;
}

输出将是对象相对于环境设置的内存。

以上就是在PHP中获取对象在内存中的大小?的详细内容,更多请关注其它相关文章!