Memory optimization in PHP array

前端 未结 3 1433
青春惊慌失措
青春惊慌失措 2020-12-04 10:35

I\'m working with a large array which is a height map, 1024x1024 and of course, i\'m stuck with the memory limit. In my test machine i can increase the mem limit to 1gb if i

3条回答
  •  眼角桃花
    2020-12-04 11:01

    In addition to the accepted answer and suggestions in the comments, I'd like to suggest PHP Judy array implementation.

    Quick tests showed interesting results. An array with 1 million entries using regular PHP array data structure takes ~200 MB. SplFixedArray uses around 90 megabytes. Judy uses 8 megs. Tradeoff is in performance, Judy takes about double the time of regular php array implementation.

提交回复
热议问题