Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The short of it is that PHP is not designed to be working with such large data structures in a memory efficient manner. Nothing you do is going to change that. Trying to work PHP within a 256MB VPS is very difficult, especially if you've got a web server and database server. </p> <p>As I illustrated in your <a href="https://stackoverflow.com/questions/6336528/memory-optimization-in-php-array">other question</a>, SplFixedArrays use less memory. That's a fact, and you can look up in the PHP source to see how the objects are created. The numbers don't lie.</p> <p>But it's only one piece of the puzzle... If you are storing lots of big things in the array or are working with other data structures, it's possible that the array isn't the "bottleneck" of memory usage.</p> <p>Regarding <code>SplFixedArray::fromArray()</code>, you will definitely be adding to your peak usage, because you are now creating two array structures. If you delete the temporary array, you will then be using less memory... but in the interim, you'll be using more.</p> <p>You'd probably use less peak memory if you just wrote your own function that shifted off an element of the temporary array one by one and added it to the SplFixedArray, as you wouldn't be duplicating your data structure size. (Due to copy-on-write, the actual savings may not be that big.)</p> <p>Again, some benchmarks of 1024*1024 sized array with 64-bit integers in each slot:</p> <pre><code>SplFixedArray: 92,914,280 array: 218,756,976 SplFixedArray::fromArray 227,147,408 peak, 92,915,088 after </code></pre> <p>So as you see, if you load fromArray, you are using more memory, but after the temporary array is deleted, it's back to the savings. But since the goal is to minimize peak memory usage, using <code>fromArray</code> will be worse than simply using arrays.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload