コード例 #1
0
ファイル: Memory.php プロジェクト: sntools/types
 /**
  * Allocates a new variable into memory.
  * @param &mixed $var Variable reference to count.
  * @return int Variable address in the memory collection
  * @throws OutOfMemoryException
  */
 public static function alloc(&$var)
 {
     $memory = self::getInstance();
     GarbageCollector::collect();
     // GC checks cycles to know if it has to actually collect or not
     if (self::$lastAddress < PHP_INT_MAX) {
         $memory[++self::$lastAddress] =& $var;
         return self::$lastAddress;
     } elseif (count($memory) == PHP_INT_MAX) {
         throw new OutOfMemoryException();
     } else {
         do {
             $address = rand(1, PHP_INT_MAX);
         } while (isset($memory[$address]));
         $memory[$address] =& $var;
         return $address;
     }
 }