简体   繁体   中英

Is there SmartHeap like Solution for Managed .NET Code?

Are there any solutions similar to SmartHeap, for optimized memory operations, for managed C# code (.net)?

http://www.microquill.com/smartheap/index.html

The .NET runtime takes care of all of the memory operations. There is no way to override the memory allocators, as doing so would dramatically change the way the GC operates, especially considering that it compacts.

That being said, this likely would provide far less benefit in .NET, as object allocation is much cheaper in the .NET world, since the memory pool is already "managed" by the CLR, and allocating new objects doesn't necessarily trigger new memory (typically it's just clearing and using already allocated memory).

SmartHeap's claim to fame, I certainly remember it from 15 years ago, is that it can avoid contention for the heap lock. The heap of a managed program doesn't have much in common with the heap used by a native program, a product like SmartHeap certainly won't be of any use.

But it does have the same kind of lock in place. It is not nearly as much as a problem as in native code, heap allocation from a garbage collected heap is very fast, it is just a pointer increment. A native heap allocator must do more work to avoid fragmentation. So the odds that two or more managed threads allocate at exactly the same time are not that great.

Nevertheless, for entirely different reasons, the .NET CLR does support multiple heaps. That feature is automatically enabled on server versions of Windows. You can force it on intentionally by using the <gcServer> element in the app.exe.config file. A side effect will be that lock contention will be very low, the real intention is to collect garbage on multiple threads simultaneously.

You can turn it on and see if it makes any noticeable difference. Beware that it does consume more memory and the garbage collection pauses might be noticeable in an interactive UI kind of program. Background collection is not available for server GC, it will become available in .NET 4.5

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM