|
|
|
|
|
by Nelkins
3350 days ago
|
|
Here's a comment that mirrors my own thoughts, from the comments on that third link[1]: "C# heap allocations aren't expensive and are faster than C/C++. They are even faster than stack allocations (if the stack alloc is too large to be a register) as the stack needs to zero out the memory first; whereas the heap has done this ahead of time. However, they do come at a cost, which is deallocation. C/C++ have both an allocation and deallocation cost. The main advantage is you know when you are paying that deallocation cost; the main disadvantage is you often do it at the wrong time or don't do it at all which leads to memory leaks, using unallocated memory or worse trashing something else's memory (as it has been reallocated). The GC isn't the bad guy; its the liver and blaming it is like blaming a hangover on the liver. However; the free drinks the clr allocation bar gives you are very tempting, and does mean there is a tendency to over indulge so the hangovers can be quite bad... (GC pauses)." [1] https://github.com/dotnet/roslyn/issues/10378#issuecomment-2... |
|