Re: Memory

From: Date: Thu, 12 Oct 2006 19:33:57 +0000
Subject: Re: Memory
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-243050@lists.php.net to get a copy of this message
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;
} ?>


« previous php.general (#243050) next »