Adobe ColdFusion 8

Passing data by reference and value

The proxy generators let you specify whether to pass parameters and return values by reference or by value.

About passing by reference and value

When you pass data by reference, the information transferred between the Java Proxy and the .NET side is a logical pointer to the underlying .NET object, which continues to reside on the .NET side. When you pass data by value, the transferred information contains a copy of the contents of the .NET object, which might or might not continue to reside on the .NET side after a function call. Passing by reference and value have different advantages.

When you pass data by reference, only changed values are passed between the Java proxy and the .NET object directly. All other information is passed as reference to its representation in the corresponding objects. Because the reference is typically much smaller than the actual object, passing by reference is typically very fast. Also, because the reference points to a .NET object that continues to exist on the .NET side, if that .NET object is updated, the updates are immediately accessible to the proxy object on the Java side. The disadvantage of reference proxies is that any access to data in the underlying object (e.g., field or method accesses) requires a round trip from the Java side to the .NET side (where the information resides) and back to the Java side.

When you pass data by value, a copy of the data is passed between .NET and Java. Because the data object itself is typically bigger than a reference, passing an object by value takes longer than passing it by reference. Also, the value that is passed is a snapshot of the object taken at the time that it was passed. The passed object maintains no connection to the underlying .NET object, therefore, the passed value does not reflect any updates to the underlying .NET object that are made after the object is passed. The advantage of passing data by value proxies is that all data in the object is local to the Java side, and field accesses are very fast, because they do not require a round trip to the .NET side and back to get the data.

The choice of whether to use reference or value proxies depends on the desired semantics of the generated proxies, and on performance.

  • In general, you should use reference proxies (the default), because they maintain the normal parameter-passing semantics of Java and C#.
  • In general, you should use value proxies in any of the following cases:
    • The class functions always must pass parameter values and return values back and forth.
    • The class object contains little data.
    • There will be frequent modification of the object data, and the object is either relatively small or the frequency of accesses to data outweighs the time taken to transfer the object.

Specifying the data passing method

When you use the JNBProxy.gui tool to generate proxies, you can designate which proxies should be reference and which should be value. The default proxy type is reference.

To set the data passing method for a class, right-click on the class in the Exposed Proxies pane. Select the desired passing method from the list that appears. After you select the passing method, the color of the proxy class changes, to indicate its type: black for reference, or blue for value (public fields/properties style).

Set the passing method for multiple proxy classes simultaneously

  1. Select Project > Pass By Reference / Value from the menu bar.
  2. The Pass by Reference / Value dialog box lists all proxy classes in the Exposed Proxies pane. Select the classes whose passing value you want to set.
  3. Click the Reference or Value (Public fields/properties) button to associate the selected classes to the desired type.
  4. Repeat steps 2 and 3 to select multiple groups of classes and set their passing methods.
  5. Click OK.