Skip to content
This repository was archived by the owner on Apr 29, 2021. It is now read-only.

Commit 8efe920

Browse files
committed
fix magic numbers
1 parent ba084d6 commit 8efe920

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

Runtime/ui/renderer/allocator/pool_object.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,19 @@ public virtual void clear() {
1515
public static class ObjectPool<TObject> where TObject : PoolObject, new() {
1616
static readonly Stack<TObject> pool = new Stack<TObject>();
1717

18+
const int POOL_MAX_SIZE = 256;
19+
const int POOL_BATCH_SIZE = 128;
20+
1821
static int allocatedCount = 0;
1922

2023
public static TObject alloc() {
2124
if (pool.Count == 0) {
22-
for (int i = 0; i < 128; i++) {
25+
for (int i = 0; i < POOL_BATCH_SIZE; i++) {
2326
var obj = new TObject();
2427
pool.Push(obj);
2528
}
2629

27-
allocatedCount += 128;
30+
allocatedCount += POOL_BATCH_SIZE;
2831
}
2932

3033
var ret = pool.Pop();
@@ -54,7 +57,7 @@ public static void release(TObject obj) {
5457
}
5558

5659
obj.clear();
57-
if (pool.Count > 256) {
60+
if (pool.Count > POOL_MAX_SIZE) {
5861
allocatedCount--;
5962
//there are enough items in the pool
6063
//just release the obj to GC

0 commit comments

Comments
 (0)