Repository navigation
Expand file tree
/
Copy pathIObjectPoolManager.cs
More file actions
103 lines (90 loc) · 3.94 KB
/
Copy pathIObjectPoolManager.cs
File metadata and controls
103 lines (90 loc) · 3.94 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
using Microsoft.Extensions.ObjectPool;
using Microsoft.IO;
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="List{T}"/>s that can be reused.
/// </summary>
/// <remarks>
/// Use <see cref="PlayerSetPool"/> if you need a set instead of a list.
/// <para>
/// The list is guaranteed to be empty when it is taken from the pool.
/// The list is automatically cleared when it is returned to the pool.
/// </para>
/// </remarks>
ObjectPool<List<Player>> PlayerListPool { get; }
/// <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; }
/// <summary>
/// Provides access to <see cref="RecyclableMemoryStream"/>s for which the buffers are pooled.
/// </summary>
RecyclableMemoryStreamManager RecyclableMemoryStreamManager { get; }
}
}