Getting size in memory of an object in PHP?

PHPServer Side ProgrammingProgramming

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.

raja
Published on 07-Apr-2020 13:16:38
Advertisements