Home / Forums / Fast Object Pooling implementation in C# with ConcurrentBag / Stack

UnreliableCode Community

Developer Research, Reverse Engineering & Coding Community

Source

Fast Object Pooling implementation in C# with ConcurrentBag / Stack

DarkLogic
Game Logic & SDK Developer
MEMBER
Rep: 180
Join Date: Jun 2024
Posts: 28
Thanks: 41
6y ago · Jul 19, 2020 2:54 PM
#1
Here is a generic lock-free ObjectPool<T> in C# for reusing expensive game entities and memory streams without GC pressure.
DarkLogic | Virtual method tables & SDKs
The following users thanked DarkLogic for this post:
ApexPredator_
Source Engine Modder
VIP
Rep: 340
Join Date: May 2022
Posts: 23
Thanks: 88
6y ago · Jul 19, 2020 7:27 PM
#2
Pre-warming the pool on startup with 100 instances completely eliminated GC collections during active combat gameplay!
ApexPredator_ · Source Engine Specialist
BoneMatrix_
CS2 & Skeleton Math
MEMBER
Rep: 190
Join Date: Aug 2024
Posts: 21
Thanks: 47
6y ago · Jul 19, 2020 9:27 PM
#3
Make sure to reset the object state in Return() so previous data does not leak into the next rented instance.
BoneMatrix_ · Source 2 Skeleton ESP & Hitboxes