forked from Unity-Technologies/UnityCsReference
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGenericPool.cs
More file actions
36 lines (32 loc) · 1.34 KB
/
Copy pathGenericPool.cs
File metadata and controls
36 lines (32 loc) · 1.34 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
// Unity C# reference source
// Copyright (c) Unity Technologies. For terms of use, see
// https://unity3d.com/legal/licenses/Unity_Reference_Only_License
namespace UnityEngine.Pool
{
/// <summary>
/// Provides a static implementation of <see cref="ObjectPool{T}"/>.
/// </summary>
/// <typeparam name="T">Type of the objects in the pool.</typeparam>
public class GenericPool<T>
where T : class, new()
{
// Object pool to avoid allocations.
internal static readonly ObjectPool<T> s_Pool = new ObjectPool<T>(() => new T(), null, null);
/// <summary>
/// Returns an object from the pool.
/// </summary>
/// <returns>A new object from the pool.</returns>
public static T Get() => s_Pool.Get();
/// <summary>
/// Get a new PooledObject which can be used to automatically return the pooled object when disposed.
/// </summary>
/// <param name="value">Output typed object.</param>
/// <returns>A new PooledObject.</returns>
public static PooledObject<T> Get(out T value) => s_Pool.Get(out value);
/// <summary>
/// Returns an object to the pool.
/// </summary>
/// <param name="toRelease">Object to release.</param>
public static void Release(T toRelease) => s_Pool.Release(toRelease);
}
}