2023-08-31

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

在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中获取对象在内存中的大小?的详细内容,更多请关注php中文网其它相关文章!

https://www.php.cn/faq/600454.html

发表回复

Your email address will not be published. Required fields are marked *