How to avoid the garbage collection in the call to COM  
Author Message
UncleSam89





PostPosted: Common Language Runtime, How to avoid the garbage collection in the call to COM Top

I got 3 party COM object with a method

int RetrieveAdjAndUnadjStock(

int MarketNumber,

int StartDate, int EndDate,

      VARIANT* IntResultArray,

VARIANT* FltResultArray).

 

IntResultArray is a 2 dimensional integer array and FltResultArray is a 2 dimensional float array.

I am making on evere run of my app 7,000-7,500 calls to this method with different parameters.

in C# interop generated by type library both IntResultArray and FltResultArray became out objects so I got boxing and to work with them I need later to unbox them. So on every call there is double construction of both arrays and destruction(and eventually garbage collection).

The first dimensions of both arrays is fixed and the second dimension is restricted(it can be computed),so those arrays can be preallocated.

So probably the best solution is to write C++ interop dll(mixed one (with native objects and managed) or ATL) where implement only methods and properties that I am actually using and in paticular call replace out object with ref int[,] and ref float[,].

How to do this

 

 




.NET Development26  
 
 
UncleSam89





PostPosted: Common Language Runtime, How to avoid the garbage collection in the call to COM Top

So what I described above called a Custom Runtime Callable Wrapper (CRCW).

Y ou can find generic sample in MSDN library at "How to: Use Native COM Servers with CRCWs"