Each array having two integers, when placed in another array representing the collection, was using around 300 bytes. The corresponding number for objects is around 350 bytes. I did some googling and found out that
a single integer value stored within an PHP array uses 68 bytes: 16 bytes for value structure (zval), 36 bytes for hash bucket, and 2*8 = 16 bytes for memory allocation headers.
No wonder an array with two named integer values takes up around 300 bytes.
how should I store a collection pair of values? array of arrays or array of objects? For memory optimization, the answer may be to have two arrays, one for each value.
For those who care for nitty-gritties, here is the program I used for measurements:
And here is a sample run:
[pankaj@fc7-dev ~]$ php -v PHP 5.2.4 (cli) (built: Sep 18 2007 08:50:58) Copyright (c) 1997-2007 The PHP Group Zend Engine v2.2.0, Copyright (c) 1998-2007 Zend Technologies [pankaj@fc7-dev ~]$ php -C memtest.php Space Used by int_array: 72492 Space Used by str_array: 88264 Space Used by arr_array: 160292 Space Used by obj_array: 180316 Space Used by arr2_array: 304344 Space Used by obj2_array: 349144 [pankaj@fc7-dev ~]$