8 ms·
Could you expand on how to avoid using GC in C#?
by tuna74 3y ago
Could you expand on how to avoid using GC in C#?
- pjmlp 3y agoValue types (structs), stack allocated arrays, spans, native memory allocation, arenas. You can also enable the warnings/errors that complain about missing using declarations for class and structs with the Dispose pattern.
- Const-me 3y agoDon’t create new objects, instead use stack and/or unmanaged heap. This reduces the expressive power of the language, for example LINQ from the standard library is probably out because based on the delegates which require memory allocations. Still, the language is very usable even without GC allocations. For example, that library re-implements a subset of ffmpeg for Raspberry Pi4 running 32-bit Linux, with no memory allocations in runtime: https://github.com/Const-me/Vrmac/tree/master/VrmacVideo https://github.com/Const-me/Vrmac/tree/master/VrmacVideo