-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathIObjectPoolManager.cs
More file actions
85 lines (74 loc) · 3.2 KB
/
IObjectPoolManager.cs
File metadata and controls
85 lines (74 loc) · 3.2 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
using Microsoft.Extensions.ObjectPool;
using SS.Utilities;
using System.Collections.Generic;
using System.IO.Hashing;
using System.Text;
namespace SS.Core.ComponentInterfaces
{
/// <summary>
/// Interface for a module that manages and tracks object pool usage.
/// </summary>
public interface IObjectPoolManager : IComponentInterface
{
/// <summary>
/// Gets the default pool for a given type and begins tracking the pool if it isn't already being tracked.
/// </summary>
/// <typeparam name="T">The type of pooled object.</typeparam>
/// <returns>The pool.</returns>
Pool<T> GetPool<T>() where T : PooledObject, new();
/// <summary>
/// Gets the known pools.
/// </summary>
IEnumerable<IPool> Pools { get; }
/// <summary>
/// Adds a pool to be tracked.
/// This is useful for monitoring private pools.
/// </summary>
/// <param name="pool">The pool to track.</param>
/// <returns><see langword="true"/> if the pool was added. <see langword="false"/> if it is already being tracked.</returns>
bool TryAddTracked(IPool pool);
/// <summary>
/// Removes a pool from being tracked.
/// </summary>
/// <param name="pool">The pool to remove from tracking.</param>
/// <returns><see langword="true"/> if the pool was removed. Otherwise, <see langword="false"/>.</returns>
bool TryRemoveTracked(IPool pool);
// TODO: add methods to free up memory by clearing pools or reducing their size
//
// Other pools
//
/// <summary>
/// Pool of <see cref="Player"/> <see cref="HashSet{T}"/>s that can be reused.
/// </summary>
/// <remarks>
/// The set is guaranteed to be empty when it is taken from the pool.
/// The set is automatically cleared when it is returned to the pool.
/// </remarks>
ObjectPool<HashSet<Player>> PlayerSetPool { get; }
/// <summary>
/// Pool of <see cref="Arena"/> <see cref="HashSet{T}"/>s that can be reused.
/// </summary>
/// <remarks>
/// The set is guaranteed to be empty when it is taken from the pool.
/// The set is automatically cleared when it is returned to the pool.
/// </remarks>
ObjectPool<HashSet<Arena>> ArenaSetPool { get; }
/// <summary>
/// A pool of <see cref="HashSet{T}"/>s for holding case insensitive names.
/// </summary>
/// <remarks>
/// Intended to hold player names or arena names.
/// For example, certain functionality may operate on player names instead of <see cref="Player"/> objects
/// when it needs to represent not only players that are currently connected, but also those that might have disconnected.
/// </remarks>
ObjectPool<HashSet<string>> NameHashSetPool { get; }
/// <summary>
/// Pool of <see cref="StringBuilder"/> objects.
/// </summary>
ObjectPool<StringBuilder> StringBuilderPool { get; }
/// <summary>
/// Pool of <see cref="Crc32"/> objects.
/// </summary>
ObjectPool<Crc32> Crc32Pool { get; }
}
}