Re: [PHP] Size of array in bytes

2001-12-20 Thread Bogdan Stancescu

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: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 To contact the list administrators, e-mail: [EMAIL PROTECTED]



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] Size of array in bytes

2001-12-20 Thread Stefan Rusterholz

Hm, I thought about that way - technically it was indeed a way to go since I
don't want to perform this action everytime but only for testing purposes
(so time doesn't matter).
But aren't arrays in PHP internally stored in a hash-like system which's
size doesn't have to be equal to the sum of it's content?
I'm more interested in how many kbytes of RAM my array is using than the
size in bytes of it's content...

But thank you anyway for helping me!
best regards
Stefan Rusterholz

 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: [EMAIL PROTECTED]
  For additional commands, e-mail: [EMAIL PROTECTED]
  To contact the list administrators, e-mail: [EMAIL PROTECTED]






-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]