返回列表 发帖

一道面试题,帮忙看看

class A{
   var $s= '+';
  function  b(){
  $this->s = str_repeat($this->s,2);
}
}

for($i=0;$i<100000;$i++){
$a = new A();
for($j=0;$j<100000;$j++){
   $a->b();
   
}
}

要求修改代码,使内存优化到最少

本帖最后由 skcks 于 2011-6-30 13:52 编辑
  1. class A{
  2.       var $s= '+';
  3.       function  b(){
  4.             $this->s = str_repeat($this->s,2);
  5.       }
  6. }

  7. $a = new A();
  8. for($j=0;$j<100000;$j++){
  9.          $a->b();
  10. }
复制代码

TOP

内存优化到最少,这个要求有点苛刻~~~~~
心要学天高
胸要学地广
永远敬佩天和地...

TOP

这个的话永不止境的

TOP

艰巨啊

TOP

class A{
        var $s = '+';
        function(){
                $this->s = str_repeat($this->,2);
        }
}

$a = new A();
for($i = 0; i < 10000; $i++){
        $a.function();
        for($j = 0; j < 10000; $j++){
                $a->b();
        }
}

TOP

发现自己实在是太菜了

TOP

返回列表