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

UnreliableCode Community

Developer Research, Reverse Engineering & Coding Community

Source

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

CanvasCrafter
UI & Custom Graphics
MEMBER
Rep: 76
Join Date: Oct 2023
Posts: 6
Thanks: 82
2y ago · Oct 1, 2023 6:57 PM
#1
Here is a generic lock-free ObjectPool<T> in C# for reusing expensive game entities and memory streams without GC pressure.
CanvasCrafter · UI & Custom Graphics
Rendering smooth 2D vector shapes, bezier paths, and ImDrawL...
The following users thanked CanvasCrafter for this post:
NetCoreAddict
.NET Architect
MEMBER
Rep: 128
Join Date: Feb 2021
Posts: 6
Thanks: 58
2y ago · Oct 1, 2023 10:04 PM
#2
Pre-warming the pool on startup with 100 instances completely eliminated GC collections during active combat gameplay!
NetCoreAddict · .NET Architect
Minimal APIs, dependency injection, and high-performance Web...
ImGuiAddict
GUI Developer
MEMBER
Rep: 261
Join Date: Sep 2022
Posts: 6
Thanks: 73
2y ago · Oct 3, 2023 3:04 AM
#3
Make sure to reset the object state in Return() so previous data does not leak into the next rented instance.
ImGuiAddict · GUI Developer
Building debug consoles, inspector panels, and telemetry das...