Poor Automatic C# Garbage Collector Performance with many C++ Interop Calls -


What C # garbage collection might fail very badly in my C # application when a well-kept GC Solving the problem? Creates millions of C ++ calls using my C # app system From time to time. Intercom Services DllImport and Calling Convention. CDCL, and some C # Destructors are for release of C ++ unmanaged memory. I am using .NET Framework 4.

  1. In my application, the code below may be due to forced paging to slow down the crawl (29 GB RAM and process on my 32GB system) It takes more than 4 minutes before hitting), while only the use of true from manual gc changes the amount of memory to about 600 MB and execution will complete within 29 seconds is?

  2. Why manual gc except for false and write to true cap memory, about 12 GB of usage and execution of the paging without permission is allowed in about 59 seconds?

    Snippet of some code (obviously by changing some names) in my application:

      Private static int callout = 0; Private constellation child manual = wrong; Private Constructive Bull Write = Incorrect; Internal constant zero usually called () {++ callCount; If (call count% 100000 == 0) {if (ManualGC) {GC.Collect (); GC.WaitForPendingFinalizers (); } If (Write) console Wrightite (HandleErrorsCallCount); } Dologic (); }   

    Memory is measured in the Memory Task Manager (Private Working Set) column in Windows Task Manager. The behavior is continuous constant.

    and some C # destructors C + + unmanaged memory

    This is not enough if your cover is small and your C ++ code requires a lot of memory, you do not put enough pressure on GC so that it can soon call its finlers. Applying IDisposable to fix this is boilerplate but not a complete solution, you should tell GC about it so that it can do something about it. Some code to play with:

      using the system; Using System.Runtime.InteropServices; Class program {static zero main (string [] args) {while (! Console.ke available) {new rapper (); }}} Class wrapper {private key int olloc = 10 * 1024; // C ++ Object Memory Usage Private Readonly Bull UsageEmp = False; // Change it after testing private INPTerm meme; Public Cover () {If (Usage Model) GC Adememari Press (Alok); mem = Marshall Olokh Geilobal (Alloc); } ~ Rapper () {martial.freejylobal (mem); If (Usage Model) GC Ramavamori Press (Alok); }}   

    When you run it, see the memory usage of this program. On my machine, the private bytes make up for almost half the gig. Now change the useamp and run again, you will see that it is more efficient than more , only 4 MB is needed without breaking the call :) test on Win 8.1 , .NET 4.5.1, you can get very different results on the older NAT version.

    You choose for alloc this is not important, it should only be in the ballpark. Obviously you need more than 10KB.

    Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -