Computer >> Computer tutorials >  >> Programming >> PHP

Getting size in memory of an object in PHP?


The memory_get_usage() function can be caked before and after allocating memory to the class created.

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;
}

Output will be the memory of object with respect to the environment setup.