Home / Forums / Fast Object Pooling implementation in C# with ConcurrentBag / Stack [Discussion #2]

UnreliableCode Community

Developer Research, Reverse Engineering & Coding Community

Source

Fast Object Pooling implementation in C# with ConcurrentBag / Stack [Discussion #2]

PacketSniffer
Network Protocols & Sockets
MEMBER
Rep: 195
Join Date: Sep 2024
Posts: 22
Thanks: 49
3y ago · Apr 1, 2023 9:03 AM
#1
Here is a generic lock-free ObjectPool<T> in C# for reusing expensive game entities and memory streams without GC pressure.
PacketSniffer | Network Protocols & Winsock SPI
The following users thanked PacketSniffer for this post:
ParanormalDev
MelonLoader / BepInEx Dev
MEMBER
Rep: 230
Join Date: Sep 2023
Posts: 21
Thanks: 58
3y ago · Apr 1, 2023 10:39 AM
#2
Pre-warming the pool on startup with 100 instances completely eliminated GC collections during active combat gameplay!
ParanormalDev | MelonLoader & ImGui Modding
CodeVoyager
C++ / Systems Dev
MEMBER
Rep: 57
Join Date: Apr 2023
Posts: 7
Thanks: 39
3y ago · Apr 2, 2023 3:39 PM
#3
Make sure to reset the object state in Return() so previous data does not leak into the next rented instance.
CodeVoyager · C++ / Systems Dev
Exploring modern C++20/23, template metaprogramming, and Lin...