I'm working on a VB6 application that consumes .NET objects via COM Interop. The application is working well, but I feel like I'm taking a performance hit each time I instantiate a .NET object from within VB6.
For example, I have VB6 code that loops through a recordset and instantiates new .NET objects for each item in the recordset and adds it to an array (CartItem
and DiscountEngine
are both .NET objects):
Set lCartItemClass = New CartItem
Set lCartItem = lCartItemClass
lCartItem.SKU = .Fields("SKU").Value
lCartItem.Quantity = .Fields("Quantity").Value
Set lCartItemsClass(i) = lCartItem
'... '
mCartClass.CartItems = lCartItemsClass
Set mDiscountEngine.Cart = mCartClass
Would I find a performance benefit by adding a factory method that takes in the parameters I want for my properties and handles the object instantiation on the .NET side of the execution? So instead of the above code, I would have something like:
mDiscountEngine.Cart.AddCartItem( .Fields("SKU").Value, _
.Fields("Quantity").Value)