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

UnreliableCode Community

Developer Research, Reverse Engineering & Coding Community

Source

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

BinaryParser
File Format Reverser
MEMBER
Rep: 128
Join Date: Nov 2024
Posts: 6
Thanks: 78
2y ago · Oct 19, 2023 12:21 PM
#1
Here is a generic lock-free ObjectPool<T> in C# for reusing expensive game entities and memory streams without GC pressure.
BinaryParser · File Format Reverser
Parsing custom binary asset formats, mesh chunks, and compre...
The following users thanked BinaryParser for this post:
ImGuiCustomizer
Custom Controls
MEMBER
Rep: 96
Join Date: Mar 2022
Posts: 6
Thanks: 95
2y ago · Oct 19, 2023 4:34 PM
#2
Pre-warming the pool on startup with 100 instances completely eliminated GC collections during active combat gameplay!
ImGuiCustomizer · Custom Controls
Creating tabs, toggle switches, and responsive layouts in De...
ThreadSafety
Concurrency Auditor
VIP
Rep: 376
Join Date: Oct 2023
Posts: 6
Thanks: 12
2y ago · Oct 19, 2023 9:34 PM
#3
Make sure to reset the object state in Return() so previous data does not leak into the next rented instance.
ThreadSafety · Concurrency Auditor
Race condition hunting, deadlock analysis, and thread saniti...