Re: My objects eats too much (and weird!) memory

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



# francisco@xxxxxxxxxx / 2007-01-26 20:40:34 +0100:
> I've written this to check memory consumption of PHP5 objects, because
> I'm having memory problems with an OO XMLParser that I've written.

It measures something else though. The memory manager doesn't allocate
memory for individual variables in PHP.

> $ php MemTest.php
> Obj1 uses 208 bytes
> Obj2 uses 168 bytes
> Obj3 uses 200 bytes
> Obj4 uses 200 bytes
> Obj5 uses 200 bytes
> Obj6 uses 200 bytes
> 
> 
> I understand that first instance may be bigger than next ones because
> method allocation and other things of that kind

No.

> but I do not understand why second instance is smaller than third :-?

It's not.
 
> In any case, my second question is: Isn't too much memory 200 bytes for
> a so simply object??

It's not memory consumption of that object.

> And the third: Is there any manner to get more compact objects in PHP5?

You need to measure something before you want to compare it ("more
compact" than what?)


> class dummy {
> 	protected $a;
> 
> 	public function __construct ( $a ) {
> 		$this->a = $a;
> 	}
> }
> 
> $before=0;
> $memdiff=0;
> 
> $before = memory_get_usage();

What's $before here?

> $obj1 = new dummy (0);
> $memdiff = memory_get_usage()-$before;
> echo "Obj1 uses $memdiff bytes\n";
> 
> $before = memory_get_usage();

What's $before here?

> $obj2 = new dummy (0);
> $memdiff = memory_get_usage()-$before;
> echo "Obj2 uses $memdiff bytes\n";

-- 
How many Vietnam vets does it take to screw in a light bulb?
You don't know, man.  You don't KNOW.
Cause you weren't THERE.             http://bash.org/?255991

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux