-
Notifications
You must be signed in to change notification settings - Fork 3
/
ArenaPool.cs
33 lines (27 loc) · 1016 Bytes
/
ArenaPool.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
using System;
using System.Collections.Generic;
using System.Text;
namespace Arenas {
public interface IArenaPoolable {
bool ResetForPool();
}
public class ArenaPool : ManagedObjectPool<Arena> {
private IMemoryAllocator allocator;
private int pageSize;
public ArenaPool(IMemoryAllocator allocator = null, int pageSize = Arena.DefaultPageSize)
: base() {
this.allocator = allocator;
this.pageSize = pageSize;
createInstance = CreateInstance;
resetInstance = ResetInstance;
}
private Arena CreateInstance() {
return new Arena(allocator ?? Arena.DefaultAllocator, pageSize);
}
private bool ResetInstance(Arena arena) {
return ((IArenaPoolable)arena).ResetForPool();
}
private static ArenaPool defaultPool = new ArenaPool();
public static ArenaPool Default { get { return defaultPool; } set { defaultPool = value; } }
}
}