Object Pooling Technology

Source: Internet
Author: User

In the ARPG page tour scene, the frequently killed monster object needs to be repeatedly generated, destroyed. Frequent triggering of garbage collection can reduce the efficiency of the game, and object pooling technology is to solve this problem

Object Pool Features:

1, the aggregation has a container, the container is equipped with the generated objects;

2, the encapsulation object generation operation;

3, the Packaging object destruction operations;

============================================================

============== Simple example of an object pool that can be automatically expanded ===========================

public class Objectpool
{
protected var pool:array = [];

protected Var Cl:class;

private var count:int = 0;

Public Function Objectpool (c:class)
{
this.cl = C;
}

/** Get instance */
Public Function GetObject ():* {
if (Pool.length > 0) {
return Pool.pop ();
}else{
Trace ("Current number of objects" + (++count));
return new Cl;
}
}

/** Recycle instance, there is no processing of OBJ's properties, it is recommended to process it yourself before recycling */
Public Function Recycle (obj:*): void{
Pool.push (obj);
}


/** Empty */
Public Function Release (): void{
Pool = [];
}
}

Object Pooling Technology

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.