Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The solution found on <a href="http://we-love-php.blogspot.de/2012/06/php-memory-consumption-with-arrays.html" rel="nofollow">http://we-love-php.blogspot.de/2012/06/php-memory-consumption-with-arrays.html</a> actually proved very helpful. I think it is worth, posting here:</p> <blockquote> <p>The most efficient kind of an array in PHP is a string.</p> </blockquote> <p>Actually storing a large number of integer values within a string (4 bytes or characters for each integer) saves more than 80% (!) of memory. Of course there are lot of disadvantages: You need to encode/decode the integers, sorting requires custom functions, etc. Therefore, this solution is only sensible when memory really matters.</p> <p>In my case, 16-bit integers were sufficient, so I could encode each integer with 2 characters. Here is the sample code I employed:</p> <pre><code>private function retrieveReferences() { $query = $this-&gt;getResultsQuery(true); $timesSE = array(); $tp = -1; // Length of $times - 1 while ($row = $query-&gt;fetchArray()) { $timeSrc = explode(',', $row['times']); // Store the times per page foreach ($timeSrc as $p=&gt;$s) { // Should be faster than checking isset $times[$p] all the time while ($p &gt; $tp) { $timesSE[] = ''; $tp = count($timesSE) - 1; } // Save to limit to 16bit (in this specific case) $i = (int)$s; if ($i &gt; 0xFFFF) { $i = 0xFFFF; } $timesSE[$p].= chr(($i &amp; 0xFF00) &gt;&gt; 8).chr($i &amp; 0x00FF); } } // Compute median for each $times[$p] // &lt;snip&gt; } </code></pre>
    singulars
    1. This table or related slice is empty.
    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. This table or related slice is empty.
    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