注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

神魔破杜梓的叨叨堂

Programming every day!

 
 
 

日志

 
 
 
 

as3对象池  

2008-10-09 09:42:25|  分类: My Tech |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |
原文来自bigroom

Two of the slow operations in the flash player are object creation and garbage collection. If we pool objects - save objects when they're no longer needed and reuse them later when another object of the same type is required - then object creation is kept to a minimum and garbage collection is reduced to zero.

Joa Ebert discussed this in his presentation at Flash on the Beach. I already use specific object pooling in the Flint particles library, but while he was talking I had an idea and wrote a class for generic object pooling of all object types. I finally had time to test the class, and it works as expected, so I've added it to my open code repository, where you can download it.

The object pool class manages pooling of all objects through two simple methods. You can obtain an object from it like this

var obj:SomeClass = ObjectPool.getObject( SomeClass );

If there are any such objects in the pool, one of them will be returned. If there are no such objects in the pool, a new one will be created and returned to you.

When you no longer need an object, you can add it to the pool for later reuse like this

ObjectPool.disposeObject( obj );

The object doesn't have to have been created through the pool - any object can be dropped into the pool with the disposeObject method.

Download source code Download the ObjectPool class.


  评论这张
 
阅读(763)| 评论(0)
推荐 转载

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017