讓變化成為計(jì)劃的一部分

          歡迎大家探討本Blog涉及的所有軟件課題。我的Google Talk ID:zhengyun(at)gmail.com。

          我最希望軟件帶給用戶的感受是:美好的體驗(yàn)、舒適感、簡(jiǎn)約、干凈...

          posts - 32, comments - 8, trackbacks - 0, articles - 0
            BlogJava :: 首頁(yè) :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理
          不知道大家有否看過“反編譯的西伯利亞攻擊源代碼”的代碼,okay,不知道它的權(quán)威性有多大,不過西伯利亞攻擊這個(gè)游戲還是有名氣的,也許值得一看。
          它的主引擎就是聲明一個(gè)靜態(tài)的圖片數(shù)組:
          class MainEngine extends FullCanvas
              
          implements Runnable
          {
          。。。。
              
          static Image imgs[];
              
          public static void initImage() {
                
          if (!isLoadImg) {
                  
          if(imgs == null)
                      imgs 
          = new Image[GameData.imgName.length];
                  
          for (int i = 0; i < GameData.imgName.length - 1; i++{
                    
          if (imgs[i] == null{
                      
          try {
                        imgs[i] 
          = Image.createImage("/" + GameData.imgName[i]);
                      }

                      
          catch (Exception ex) {
                        System.out.println(
          "i:"+i);
                        ex.printStackTrace();
                      }

                    }

                    percent 
          = (i * 100/ (GameData.imgName.length - 1);
                    Sib.engine.flushGraphic();
                  }

                  isLoadImg 
          = true;
                }

              }

          而且我搜索了它的5個(gè)java文件,它在什么情況下調(diào)用System.gc()呢?
          下面三種情況:
          用戶返回游戲時(shí)(可能之前去接聽電話了?或者去設(shè)置里改參數(shù)了?);
          用戶選完飛機(jī)后,這可能是一個(gè)選項(xiàng)菜單,選飛機(jī)時(shí)所用到的資源可能以后在游戲中沒必要用,所以及時(shí)回收一下;
          顯示過關(guān)界面時(shí),這時(shí)候有卡的現(xiàn)象,歡喜的用戶也不會(huì)在意的。

          除此之外就沒有了。

          Nokia 的文檔Known Issues In The Nokia 6600 MIDP 2.0 Implementation v1.7說:
          2.15.1 Garbage collecting
          Description
          Calling the System.gc() method results in extreme slowness and jamming. In Monty 1.0 VM, garbage
          collection is different and every time System.gc is called, the entire memory is really cleared.
          This is an extremely slow process!
          Solution
          Do not call the System.gc method at all, or call the System.gc() garbage collecting method only
          in non-time-critical situations, such as screen transitions, state transitions, pause states,
          etc. If the System.gc() method is used, it is recommended to add a short delay (~20-50 ms) after
          the method call to ensure the sufficient time for the garbage collection, as in the following

          example
          System.gc();
          Thread.sleep(delay); delay = 20-50 ms


          評(píng)論

          # re: 什么時(shí)候在游戲中調(diào)用System.gc()?[javaME]  回復(fù)  更多評(píng)論   

          2008-03-21 22:15 by univasity
          謝謝分享,不錯(cuò)的建議。
          主站蜘蛛池模板: 石嘴山市| 民县| 遵化市| 定陶县| 清丰县| 商都县| 黄大仙区| 全州县| 竹溪县| 明水县| 蒲江县| 柯坪县| 凤凰县| 休宁县| 广南县| 淄博市| 句容市| 敦煌市| 仪征市| 金沙县| 大邑县| 吴桥县| 麟游县| 西青区| 昌乐县| 象山县| 临洮县| 米泉市| 来凤县| 睢宁县| 怀宁县| 额敏县| 盐城市| 苍溪县| 曲沃县| 额济纳旗| 永川市| 威宁| 广安市| 河津市| 伊宁市|