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 could
or 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 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 (for example, 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 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, use reference proxies (the default), because they maintain
the normal parameter-passing semantics of Java and C#.
In general, 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.
The object data changes frequently, 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 the proxies that pass
by reference and which proxies pass by 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).