Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

13 Commits

Repository files navigation

PoolingLib

Paint 3D

📖 English

Overview

PoolingLib is a lightweight object pooling library for .NET, reusing common objects to reduce memory allocations.

  • Get() retrieves an object from the pool (creates if empty).
  • Return() returns the object back to the pool.

📦 Supported Types

Collection PoolBase
ListPool<TObject>List<TObject>
LinkedListPool<TObject>LinkedList<TObject>
QueuePool<TObject>Queue<TObject>
StackPool<TObject>Stack<TObject>
ConcurrentBagPool<TObject>ConcurrentBag<TObject>
CollectionPool<TObject>Collection<TObject>
HashSetPool<TObject>HashSet<TObject>
SortedSetPool<TObject>SortedSet<TObject>
Dictionary PoolBase
DictionaryPool<TKey, TValue>Dictionary<TKey, TValue>
SortedDictionaryPool<TKey, TValue>SortedDictionary<TKey, TValue>
Special PoolBase
StringBuilderPoolStringBuilder
MemoryStreamPoolMemoryStream

Usage Example

// Get a pooled List<int>varlist=ListPool<int>.Pool.Get();list.Add(1);list.Add(4);list.Remove(1);Console.WriteLine(list.Count);// Output: 1// Return the list to the poolListPool<int>.Pool.Return(list);

📖 中文

简述

PoolingLib 是一个用于.NET的轻量级对象池库,通过复用对象来减少内存分配。

  • Get() 从池中获取一个对象 (如果为空则创建)。
  • Return() 将对象返回至对象池。

📦 支持的类型

集合池基类
ListPool<TObject>List<TObject>
LinkedListPool<TObject>LinkedList<TObject>
QueuePool<TObject>Queue<TObject>
StackPool<TObject>Stack<TObject>
ConcurrentBagPool<TObject>ConcurrentBag<TObject>
CollectionPool<TObject>Collection<TObject>
HashSetPool<TObject>HashSet<TObject>
SortedSetPool<TObject>SortedSet<TObject>
字典池基类
DictionaryPool<TKey, TValue>Dictionary<TKey, TValue>
SortedDictionaryPool<TKey, TValue>SortedDictionary<TKey, TValue>
特殊池基类
StringBuilderPoolStringBuilder
MemoryStreamPoolMemoryStream

使用示例

// 获取一个池化过的List<int>varlist=ListPool<int>.Pool.Get();list.Add(1);list.Add(4);list.Remove(1);Console.WriteLine(list.Count);// 输出: 1// 将List<int>返回至列表ListPool<int>.Pool.Return(list);

About

A simple pooling library for dotnet

Topics

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages