Re: Memory

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Maybe I'm doing my math wrong here, but for 1 to 999999999, make a string 9 bytes long, 10 including terminating null. (And PHP probably includes a little extra for overhead)...

999999999 * 10 bytes = 9999999990 bytes -> that's about 9 and a half gigs...

jon

Doug Fulton wrote:
I'm running out of memory even though I upped it to "memory_limit = 500M" in php.ini.
Error messages and script are below.  Thanks in advance for any tips.

$ php -c /usr/local/php5/lib/php.ini createPseudoIDs.php > crosswalk.txt
php(780) malloc: *** vm_allocate(size=1069056) failed (error code=3)
php(780) malloc: *** error: can't allocate region
php(780) malloc: *** set a breakpoint in szone_error to debug
FATAL:  emalloc():  Unable to allocate 37 bytes



<?php
////////////////////////////////////////////////////////////////////
// Create a complete mapping of SSNs to random "Pseudo Keys"
////////////////////////////////////////////////////////////////////

// Create array with all potential Pseudo Keys
$pseudoKeys = array();
for ($i=1;$i<=999999999;$i++) {
    $pseudoKeys[] = padToNine($i);
}

// Loop through all possible SSNs
$numLeft = 999999999;
for ($i=1;$i<=999999999;$i++) {
    $ssn = padToNine($i);
    // Get random index into remaining pseudo keys
    $maxRand = $numLeft-- - 1;
    $randIndex = rand(0, $maxRand);
    $pseudoKey = $pseudoKeys[$randIndex];
    array_splice($pseudoKeys,$randIndex,1);
    // Output it.
    print $ssn.":".$pseudoKey."\n";
}

function padToNine($num) {

    $final = '';

    $cnt = strlen(strval($num));
    $padding = 9 - $cnt;
    for ($i=1; $i<=$padding; $i++) {
        $final .= '0';
    }
    $final .= strval($num);

    return $final;
}
?>


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux