zoukankan      html  css  js  c++  java
  • 对象池

    package  
    { 
        import flash.display.Sprite; 
         
        public final class SpritePool 
        { 
            //定义对象池的最大尺寸
            private static var MAX_VALUE:uint;
            //对象池增长补偿   不能缺一个 就补一个吧 
            private static var GROWTH_VALUE:uint;
            //当前对象池里空闲可用的对象数目
            private static var counter:uint; 
            //对象池
            private static var pool:Vector.<Sprite>; 
            private static var currentSprite:Sprite; 
              //初始化对象池   存取满对象
            public static function initialize( maxPoolSize:uint, growthValue:uint ):void 
            { 
                MAX_VALUE = maxPoolSize; 
                GROWTH_VALUE = growthValue; 
                counter = maxPoolSize; 
                 
                var i:uint = maxPoolSize; 
                 
                pool = new Vector.<Sprite>(MAX_VALUE); 
                while( --i > -1 ) 
                    pool[i] = new Sprite(); 
            } 
             
            public static function getSprite():Sprite 
            { 
                if ( counter > 0 ) 
                    return currentSprite = pool[--counter]; 
                //如果对象池存量不够了 则再续      GROWTH_VALUE 个新对象补充
                var i:uint = GROWTH_VALUE; 
                while( --i > -1 ) 
                        pool.unshift ( new Sprite() ); 
                counter = GROWTH_VALUE; 
                return getSprite(); 
                 
            } 
      
            public static function disposeSprite(disposedSprite:Sprite):void 
            { 
                pool[counter++] = disposedSprite; 
            } 
        } 
    }
  • 相关阅读:
    hdu2089 不要62
    hdu4734 F(x)
    hdu3555 Bomb
    hdu3652 B-number
    hdu4352 XHXJ's LIS
    CodeForces 55D Beautiful numbers
    数位dp模板
    欧拉函数模板
    UVALive
    常用正则表达 (转)
  • 原文地址:https://www.cnblogs.com/naiking/p/2987034.html
Copyright © 2011-2022 走看看