C++ and Grasshopper passing native variables from one component to another

Hi,

I am wrapping some native C++ library variables to C#.
Before I had one C# component where I had everything working fine calling CLI wrapped variables and solver. But now I want to distribute my code into multiple components.

The thing is that I disposed some variables by placing them into brackets so that jointElementMatsSet and ele_link_tnl2 are deleted. I could also call Dispose method.
The small bit of code is here:

{
  var jointElementMatsSet = new OpenSees.Materials.Uniaxials.UniaxialMaterialWrapper[] { Axial_perimeter_long_leftMat, Shear_1_perimeter_long_leftMat, rigidmattagMat, FreemattagMat, FreemattagMat, FreemattagMat };
  var ele_link_tnl2 = new OpenSees.Elements.TwoNodeLinkWrapper(2, 3, 16, 1601, dirIds2, jointElementMatsSet, new OpenSees.VectorWrapper(new double[] { 1, 0, 0 }), new OpenSees.VectorWrapper(new double[] { 0, 0, 1 }), new OpenSees.VectorWrapper(0), new OpenSees.VectorWrapper(0), 0, 0);
  theDomain.AddElement(ele_link_tnl2);
}

But now since I want to distribute different classes into different components I have a question:
Can I create one variable in one component and dispose it in another one?
More simply: when two components are connected and second component receives the variable, is it duplicated or it points to the same memory location?

I don’t see why not. Objects that inherit from IDisposable are usually holding onto a C++ pointer via an IntPtr object. So it’s just a matter of disposing, which involved deleting the C++ object.

– Dale

Does it mean that in grasshopper when you pass data from one component to another parameters are not duplicated and are referenced to the same address in memory?

This is dependent on what you are passing and on what components are involved. But if this is all your own stuff, then the reference (e.g. pointer) is passed.

– Dale

1 Like