我一直在研究opengl es,我看到的一个示例是使用“ Pool”类来跟踪触摸和键盘事件。
有人可以解释为什么以及为什么需要泳池课程。从我阅读的内容来看,它与垃圾收集和限制输入类的数量有关。
这对我来说似乎有点抽象,所以如果有人可以解释发生了什么,我将不胜感激,我将在此处粘贴一些代码:
public Pool(PoolObjectFactory < T > factory, int maxSize) {
this.factory = factory;
this.maxSize = maxSize;
this.freeObjects = new ArrayList < T > (maxSize);
}
public T newObject() {
T object = null ;
if (freeObjects.isEmpty())
object = factory.createObject();
else
object = freeObjects.remove(freeObjects.size() - 1);
return object;
}
public void free(T object) {
if (freeObjects.size() < maxSize)
freeObjects.add(object);
}
PoolObjectFactory <TouchEvent> factory = new PoolObjectFactory <TouchEvent> () {
@Override
public TouchEvent createObject() {
return new TouchEvent();
}
Pool <TouchEvent> touchEventPool = new Pool <TouchEvent> (factory, 50);
TouchEvent touchEvent = touchEventPool.newObject();
. . . do something here . . .
touchEventPool.free(touchEvent);
谢谢!