Need an array-like structure in PHP with minimal memory usage

后端 未结 8 2171
星月不相逢
星月不相逢 2020-12-23 02:02

In my PHP script I need to create an array of >600k integers. Unfortunately my webservers memory_limit is set to 32M so when initializing the array the script a

相关标签:
8条回答
  • 2020-12-23 02:57

    You can try to use a SplFixedArray, it's faster and take less memory (the doc comment say ~30% less). Test here and here.

    0 讨论(0)
  • 2020-12-23 03:00

    A PHP Judy Array will use significantly less memory than a standard PHP array, and an SplFixedArray.

    I quote "An array with 1 million entries using regular PHP array data structure takes 200MB. SplFixedArray uses around 90 megabytes. Judy uses 8 megs. Tradeoff is in performance, Judy takes about double the time of regular php array implementation."

    0 讨论(0)
提交回复
热议问题