No, PHP does not have the strict equivalent of std::vector .
We just use multipurpose arrays or one of the additional datastructures in SPL , namely SplFixedArray , ArrayObject and some Heaps and Stacks , but none of them are actually equivalent.
The closest I can think of to save memory is the PECL extension for Judy arrays :
PHP Judy implements sparse dynamic arrays (also called Judy arrays). This extension is based on the Judy C library. The Judy array only consumes memory when it is populated, but can grow to use all available memory if desired. Judy's main advantages are scalability, high performance, and memory efficiency.
It supports the following modes:
BITSET - Define Judy array as bitset with keys as Integer and Values as logicalINT_TO_INT - Define a Judy array with key / values as Integer and Integer.INT_TO_MIXED - Define a Judy array with keys as Integer and values of any type.STRING_TO_INT Define a Judy array with keys as String and values as Integer and Integer.STRING_TO_MIXED - Define a Judy array using the keys as a string and values of any type.
You probably want INT_TO_MIXED . As I said, this is the closest thing I can think of. This is not the same. I have never used it before, so I can’t say if it meets your requirements in terms of efficiency.
You can view the source code http://lxr.php.net/xref/PECL/Judy/
Gordon
source share