Re: Size of array in bytes

From: Date: Thu, 20 Dec 2001 12:47:53 +0000
Subject: Re: Size of array in bytes
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-78315@lists.php.net to get a copy of this message
Had the same problem not long ago and I didn't find a simple solution either. My solution at the time was the painfully slow one - walking the array and storing strlen for both key and value. Since you have a large array, this probably doesn't do for you. A faster but less accurate solution would be storing round(strlen(serialize($array))*$coefficient), where you should approximate $coefficient for your average array (the less the average array element size, the smaller the coefficient). I know, these are both rudimentary and ugly solutions but I didn't find any better - these are the solutions I considered when I had the same problem. Bogdan Stefan Rusterholz wrote: > Hi > > I have a rather large array in my script and I was interested how much > memory it uses. Is there a way to get the size of an array in bytes? > BTW: I did RTFM and didn't find an accomidating function, so if there is > one, please point me to it... > > TIA > Stefan Rusterholz > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net

« previous php.general (#78315) next »