About pass-by-reference

From my current understanding, the recommended way (with ARC enabled) of 'pass by reference' is like:
    -(void)somefunc:(someclass **)byref;
    // and 'someclass **' should be inferred to 'someclass * __autoreleasing *'
    // am i right?
    //or we could just explicitly define it like
    -(void)somefunc:(someclass * __autoreleasing *)byref;
However, from the answer to this thread, http://stackoverflow.com/questions/8814718/handling-pointer-to-pointer-ownership -issues-in-arc.
It seems -(void)somefunc:(someclass *__strong *)byref could do the trick as well (in demo2 of above link).
    1.-(void)somefunc:(someclass * __autoreleasing *)byref;
    2.-(void)somefunc:(someclass *__strong *)byref
For the first one, as documented by Apple it should be implicitly rewritten by compiler like this:
    NSError * __strong error;
    NSError * __autoreleasing tmp = error;
    BOOL OK = [myObject performOperationWithError:&tmp];
    error = tmp;
It seems the second one has a better performance? Because it omits the process of 'assign the value back' and 'autoreleasing'. But I rarely see functions declared like this. Is it a better way to use the second function to do the 'pass by reference' job?
Any suggestion or explanation? Thanks in advance.

Why do you need to do this? Because Objective-C is based on pointers rather than objects, you already have pass by reference. In C++ it is a big deal to pass objects by value compared to by reference. Just passing by pointer, as in the case with Objective-C, is usually all you need for pass by reference. It is only in rare circumstances that you really need to pass a pointer and have the pointer itself get changed. Apple does this to return error pointers. That is only because so many programmers are unable to do exceptions properly.

Similar Messages

  • Confused about passing by reference and passing by valule

    Hi,
    I am confuse about passing by reference and passing by value. I though objects are always passed by reference. But I find out that its true for java.sql.PreparedStatement but not for java.lang.String. How come when both are objects?
    Thanks

    Hi,
    I am confuse about passing by reference and passing
    by value. I though objects are always passed by
    reference. But I find out that its true for
    java.sql.PreparedStatement but not for
    java.lang.String. How come when both are objects?
    ThanksPass by value implies that the actual parameter is copied and that copy is used as the formal parameter (that is, the method is operating on a copy of what was passed in)
    Pass by reference means that the actual parameter is the formal parameter (that is, the method is operating on the thing which is passed in).
    In Java, you never, ever deal with objects - only references to objects. And Java always, always makes a copy of the actual parameter and uses that as the formal parameter, so Java is always, always pass by value using the standard definition of the term. However, since manipulating an object's state via any reference that refers to that object produces the same effect, changes to the object's state via the copied reference are visible to the calling code, which is what leads some folk to think of java as passing objects by reference, even though a) java doesn't pass objects at all and b) java doesn't do pass by reference. It passes object references by value.
    I've no idea what you're talking about wrt PreparedStatement, but String is immutable, so you can't change its state at all, so maybe that's what's tripping you up?
    Good Luck
    Lee
    PS: I will venture a guess that this is the 3rd reply. Let's see...
    Ok, second. Close enough.
    Yeah, good on yer mlk, At least I beat Jos.
    Message was edited by:
    tsith

  • Passing a reference to a type definition to a SubVI

    I have created a type definition that I would like to use across my application. This particular type definition is also the front panel control to my top level VI. I wanted to pass a reference to this control to my SubVi's so that they could dereference as needed and in very rare cases update the values on the front panel. However, as I built the application I noticed that I was breaking the control reference as I updated the type definition. This implies that they type of the reference changes as I change the type definition.
    How do I go about building the reference I need or is there some other way to do this that works just as well. Even if I can't make a reference to the control that is tied to the type definition, I'm willing to pass in a variant who can house the reference as long as I can build the data type (the reference) inside my SubVis.
    Solved!
    Go to Solution.

    Okay, so I tried all three approaches in a SubVI, here's what happened.
    My approach was simply to create a Type Def control, right-click and create a Reference. Then create a control from that reference by right-clicking the output of the reference and selecting the Create Control option. I then pasted this 'cluster' reference into my SubVi, made it an input and then wired up the reference in the parent to the control in the SubVi.
    Result: This breaks when you update the Type Definition.
    Next, Ben's approach (or my best effort at doing what he suggested). I created a control from reference to the type def. I cut it from the parent VI and pasted it into a new type def. I then put the type def in the SubVI and set it as an input.
    Result: This breaks when you update the Type Definition (but it actually takes a bit longer for the error to propogate).
    Finally, Christian's solution (or my best effort). I took the type def reference and put it through a To More Generic Class guy, casting it to a Control Refnum. I put a Control Refnum on the front panel of my SubVI and wired it to a To More Specific Class guy. I created a control of the type def in the subvi, hid it, and created a reference. I wired the reference to the more specific guy and verified I was getting the right data.
    Result: It works!
    It's possible I just didn't understand how to make the reference type def you were referring to Ben. I would prefer a method with less verbage. I pass this refnum into a class which holds it. Since I can't replicate the type exactly prior to run time (i.e. create a control that is exactly a reference to the type definition of my front panel), I have to save the reference as a Control Refnum and cast it every time I need it (i.e. create a control from the typedef, create a reference frome the type def, etc). More verbage than optimal, but still good!
    Thanks for the help.

  • Passing control reference to subVI crashes labview

    Hi,
    using a image control (as indicator) provided by imaq Vision, I tried to pass the reference of the control to a subVI. On a computer it works and on a other (same labview version, same vision version, same os, same hardware and hardware drivers!), this crashes labview. I tried to close the control refnum at the end of the subVI, but that changed nothing to the issue. Now I use the reference as a global variable and it seems to work...nevertheless, I would like to understand what the issue and if I should remove any passing to subVI of control ref because this can potentially triggers an error. My correlated question is if this global passing is a "fake" workaround or have real chance of improving (this before going through the whole code for changing all passing of reference to subVI)
    thanks a lot

    Hi,
    thank CoastalMaineBird for your answer
    How do you know it's this issue which causes the crash?
    When I remove this parameter from and the only property node in the subVi that write to it, I have no longer any problem. Moreover, to ensure that's really the "passing", and made a global variable containing the reference to this control and use my original SubVi that do access the control through its reference number
    , and it works! In this last exemple, the only change is the way of transmitting the reference
    What LabVIEW version?
    8.0.1
    up to date according Measurement & Automation update tool
    Given that one computer works OK, and another crashes, I would say that
    you are seeing the effect of something else, not the cause. If passing
    a control ref via terminals was fatal, it would be fatal all the time.
    You have some other sort of issue, perhaps timing of the different
    machines triggers the bug, perhaps running out of memory, perhaps
    LabVIEW is corrupted on one machine.... But I don't think changing all
    your code to use globals would solve the real problem. Actually, saying that I wonder about problem of synchronisation. I know from Visual C++ that this kind of error happens if two process try to access the same control at the same time. This is typically an error changing from a computer to an other, and mutex or semaphore are the way to deal nicely with that. But does labview contains already such a securisation? If so, the global variable point on a single object and can "fell" the semaphore/mutex. But passing make a copy that will likely have two different semaphore/mutex but will point to a single control! Do someone know if I'm wrong in this idea or not?
    Thanks

  • Passing object references to methods

    i got the Foo class a few minutes ago from the other forum, despite passing the object reference to the baz method, it prints "2" and not "3" at the end.
    but the Passer3 code seems to be different, "p" is passed to test() , and the changes to "pass" in the test method prints "silver 7".
    so i'm totally confused about the whole call by reference thing, can anyone explain?
    class Foo {
        public int bar = 0;
        public static void main(String[] args) {
                Foo foo = new Foo();
                foo.bar = 1;
                System.out.println(foo.bar);
                baz(foo);
                // if this was pass by reference the following line would print 3
                // but it doesn't, it prints 2
                System.out.println(foo.bar);
        private static void baz(Foo foo) {
            foo.bar = 2;
            foo = new Foo();
            foo.bar = 3;
    class Passer2 {
         String str;
         int i;
         Passer2(String str, int i) {
         this.str = str;
         this.i = i;
         void test(Passer2 pass) {
         pass.str = "silver";
         pass.i = 7;
    class Passer3 {
         public static void main(String[] args) {
         Passer2 p = new Passer2("gold", 5);
         System.out.println(p.str+" "+p.i);  //prints gold 5
         p.test(p);
         System.out.println(p.str+" "+p.i);   //prints silver 7
    }

    private static void baz(Foo foo) {
    foo.bar = 2;
    foo = new Foo();
    foo.bar = 3;This sets the bar variable in the object reference by
    foo to 2.
    It then creates a new Foo and references it by foo
    (foo is a copy of the passed reference and cannot be
    seen outside the method).
    It sets the bar variable of the newly created Foo to
    3 and then exits the method.
    The method's foo variable now no longer exists and
    now there is no longer any reference to the Foo
    created in the method.thanks, i think i followed what you said.
    so when i pass the object reference to the method, the parameter is a copy of that reference, and it can be pointed to a different object.
    is that correct?

  • What is the use of passing object reference to itself ?

    What is the use of passing object reference to itself ?
    regards,
    namanc

    There is an use for returning an object reference from itself, for instance:
    class C {
    public:
         C append(C c) {
             // do something interesting here, and then:
             return this;
    }You can "chain" calls, like this:
    C c = new C();
    C d = new C();
    C e = new C();
    c.append (d).append (e);Maybe the OP has "inverted" the common usage, or thought about a static method of a class C that requires a parameter of type C (effectively being a sort of "non-static method").
    class C {
        static void doAnotherThing (C c) {
            c.doSomething(); //-- effectively C.doAnotherThing(c) is an "alternative syntax" for c.doSomething()

  • Pass "this" reference within SessionBean to other classes

    Can "this" reference for a SessionBean be passed to other helper classes?
    For example,
    public class MySb implements SessionBean {
    MyClass a = new MyClass();
    public void myBusinessMethod() {
    a.methodA(this);
    It looks strange that MyClass.methodA is expecting a SessionBean as opposed to a EJBObject interface as parameter. I also thought about passing the SessionContext object. Can someone tell me the pros and cons?
    Thank you.

    Thanks for the reply.
    There are disadvantages using the EJBObject directly. However, since the call always comes from the EJBObject instance and the helpers simply call its methods within the same method call. For performance reason, will it hurt to do that? i.e.
    public class MyStatefulSessionBean ... {
    public void methodA() {
    helperA.methodA(this, parms);
    void changeState(StateHelper helper){this.helper=helper;}
    class helperA {
    methodA(EJBObject obj, parms){
    obj.changeState(new HelperB);
    My other alternative is to pass the SessionContext to the helpers and helpers can call its getObject() to retrieve the remote interface. Then performance suffers and unwanted private method (changeState) has to be exposed to the public interface.

  • Strings are passed by Reference

    Since strings are objects, they are passed by reference. I tested this out:
    1.in main(): String str="in main"; creates a new string "in main" and has str point to it.
    2.Passed str into changeStr(String str2)
    3.in changeStr: str2="in changeStr", since str2 is a reference, it should redirect str to point to the new string "changeStr".
    4.Back in main I print out str and get "in main".
    Why?

    (When you post source code, please put it in CODE tags; there's a button for that above the textarea.)
    Don't think of references as memory addresses; that makes them sound like C pointers, when in fact they're fundamentally different: a pointer points to a memory location, while a reference points to an Object. C lets you dereference a pointer and replace the data at that memory location with something else. Afterward, any existing variable that referred to the data in that section of memory, will see the new value.
    A Java reference lets you access the object to call its methods, examine its variables, and so on. If the object is mutable, you can change itss contents, and all existing variables that refer to that object will see those changes. But you can't replace the whole object with something else. Reassigning the variable that was passed into the method has no effect on the original object or on any other variables that pointed to it.
    So stop thinking of references as memory addresses. In fact, stop thinking about memory addresses, period. You never need that information in Java, and for that you should be eternally grateful. The absence of C pointers was one of Java's biggest selling points, way back when.
    Edited by: uncle_alice on Feb 27, 2008 7:55 AM
    Oh well. :-/ At least I may have done some good by asking the OP to use CODE tags.

  • Is possible pass class reference into function by reference ?

    Hello, here is one example.
    class MyClass
    public int i;
    public static void Change(MyClass param1, MyClass param2)
    MyClass temp;
    temp = param1;
    param1 = param2;
    param2 = temp;
    public static void main(String[] args)
    MyClass param1 = new Main();
    param1.i = 100;
    MyClass param2 = new Main();
    param2.i = 200;
    Change(param1,param2);
    System.out.println(param1.i);
         System.out.println(param2.i);
    Is clear the result will be :
    100
    200
    Well, is possible in java pass into function object reference by reference? (for example in C# exist keyword ref, which solve this problem.) Other question is if this is something what is really needed in daily programming life, but I'm curious.
    Thanks for response

    iaragorn wrote:
    Well, is possible in java pass into function object reference by reference? No. Java only passes by value.
    Other question is if this is something what is really needed in daily programming lifeNope. Java has done just fine without pass by reference for about 12 or 14 years now.

  • How do you pass vi references from one event to another

    I have a vi which gets vi references (thereby loading the vi's into memory) for all the vi's in a given directory when a user clicks a button on the front panel. To do this I use an event structure. My question is whether it is possible to have another event (user button on the front panel) which unloads the vi's from memory. I have tried passing the vi references that are initially generated to the close reference function but whenever I do I get a 'vi reference invalid' error. Does this have to do with trying to pass the vi references between one event and another? If I use a local variable simply pass a reference to another indicator and then probe it, the originally-generated refnum and the local vari
    able refnum match up. However once I try to wire that same indicator to the close reference function I get the 'vi reference invalid' error. Is there a different/better way to unload the vi's from memory based on a user button click? Any suggestions would be welcome.
    Jason
    Attachments:
    Load_Directory_of_vi's.vi ‏57 KB

    Several problems with your code:
    1... Bad idea to use lights as buttons. Yes it can be done, but it's not "natural".
    2... If you've gotta do that, set their mechanical action to "LATCH WHEN RELEASED"
    3... Because of #2, you are getting TWO copies of every array when you click the LOAD VIs light (er... button).
    4... No need for the conversion from path to string and back - use BUILD PATH to append each file name to he folder path.
    5... Set the BROWSE OPTIONS on your PATH control to EXISTING DIRECTORY to allow browsing of directories, not files.
    6... Your code doesn't care whether the file is a .VI file, or a .ZIP file, or a .TXT file, or what. Use the PATTERN input on the LIST function to discriminate.
    7... Your code is only storing the latest refer
    ence, not the array of references.
    8... An ERROR DIALOG on the OPEN REFERENCE function will tell you that you're getting an error. Why? You are asking to prepare a non-reentrant VI for reentrant execution (why use options = 8?)
    9... Because of #8, the latest VI reference is invalid.
    Steve Bird
    Culverson Software - Elegant software that is a pleasure to use.
    Culverson.com
    Blog for (mostly LabVIEW) programmers: Tips And Tricks

  • Drag and Drop - Transferable, how to pass a reference? (URGENT)

    I've a tree that supports drag and drop correctly but every time I exchange a node position the old parent instance remaining on the tree is different from the one I was referencing with the dragged child before the drag occurred. I absolutely need to maintain all references and cannot work with copies.
    Is there any way to use the Transferable interface to pass the original object instead of a copy?
    Thanks to Tedhill who raised the problem, trying to get a quick answer.
    ;o)

    hi guys let me close this thread:
    Thanks to asjf and sergey35 who helped me.
    Actually the isDataFlavorSupported method you suggest passes a reference and not a copy.
    Too bad I fell into another problem with the reloading of the
    moving-node Object after the DnD.
    But finally the working code is:
    public class XJTreeDnD extends XJTree implements DragGestureListener, DragSourceListener, DropTargetListener{
      private DefaultMutableTreeNode dragNode = null;
      private TreePath dragParentPath = null;
      private TreePath dragNodePath = null;
      private DragSource dragSource;
      private DropTarget dropTarget;
      private TransferableTreePath transferable;
      private boolean DnDEnabled = true;
      //private boolean CnPEnabled = false;
      public XJTreeDnD(XNode node) {
        super(node);
        // Set up the tree to be a drop target.
        dropTarget = new DropTarget(this, DnDConstants.ACTION_MOVE, this, true);
        // Set up the tree to be a drag source.
        dragSource = DragSource.getDefaultDragSource();
        dragSource.createDefaultDragGestureRecognizer(this, DnDConstants.ACTION_MOVE, this);
      private DefaultMutableTreeNode getTreeNode(Point location) {
        TreePath treePath = getPathForLocation(location.x, location.y);
        if (treePath != null) {
          return((DefaultMutableTreeNode) treePath.getLastPathComponent());
        } else {
          return(null);
    //dragGesture implementation
        public void dragGestureRecognized(DragGestureEvent e) {
          if(DnDEnabled){
            TreePath path = this.getSelectionPath();
            if (path == null || path.getPathCount() <= 1) {
              System.out.println("Error: Path null, or trying to move the Root.");
              return;
            dragNode = (DefaultMutableTreeNode) path.getLastPathComponent();
            dragNodePath = path;
            dragParentPath = path.getParentPath();
            transferable = new TransferableTreePath(path);
            // Start the drag.
            e.startDrag(DragSource.DefaultMoveDrop, transferable, this);
    //dragSource implementation
        public void dragDropEnd(DragSourceDropEvent e) {
          try {
            if (e.getDropSuccess()) {
              ((BaseXJTreeModel)this.getModel()).removeNodeFromParent(dragNode);
              DefaultMutableTreeNode dragParent = (DefaultMutableTreeNode) dragParentPath.getLastPathComponent();
              XNode xnodeParent = (XNode)dragParent.getUserObject();
              ((BaseXJTreeModel)this.getModel()).valueForPathChanged(dragParentPath, xnodeParent);
          } catch (Exception ex) {
            ex.printStackTrace();
        public void dragEnter(DragSourceDragEvent e) {
          // Do Nothing.
        public void dragExit(DragSourceEvent e) {
          // Do Nothing.
        public void dragOver(DragSourceDragEvent e) {
          // Do Nothing.
        public void dropActionChanged(DragSourceDragEvent e) {
          // Do Nothing.
    //dropTarget implementation
        public void drop(DropTargetDropEvent e) {
          try {
            Point dropLocation = e.getLocation();
            DropTargetContext dtc = e.getDropTargetContext();
            XJTreeDnD tree = (XJTreeDnD) dtc.getComponent();
            TreePath parentPath = tree.getClosestPathForLocation(dropLocation.x, dropLocation.y);
            DefaultMutableTreeNode parent = (DefaultMutableTreeNode)parentPath.getLastPathComponent();
            Transferable data = e.getTransferable();
            DataFlavor[] flavors = data.getTransferDataFlavors();
            for (int i=0;i<flavors.length;i++) {
              if (data.isDataFlavorSupported(flavors)) {
    e.acceptDrop(DnDConstants.ACTION_MOVE);
    TreePath movedPath = (TreePath) data.getTransferData(flavors[i]);
    DefaultMutableTreeNode treeNodeMoved = (DefaultMutableTreeNode) movedPath.getLastPathComponent();
    DefaultMutableTreeNode treeNodeLeft = (DefaultMutableTreeNode) this.dragNodePath.getLastPathComponent();
    XNode xnodeParent = (XNode)parent.getUserObject();
    XNode xnodeChild = (XNode)treeNodeLeft.getUserObject();
    /** @todo check the parent whether to allow the drop or not */
    if(xnodeParent.getPath().startsWith(xnodeChild.getPath())){
    System.out.println("cannot drop a parent node on one of its children");
    return;
    if(xnodeParent.getPath().getPath().equals((xnodeChild.getPath().getParentPath()))){
    System.out.println("node is already child of selected parent");
    return;
    // Add the new node to the current node.
    xnodeParent.addChild(xnodeChild);
    ((BaseXJTreeModel)this.getModel()).valueForPathChanged(parentPath, xnodeParent);
    ((BaseXJTreeModel)this.getModel()).insertNodeInto(treeNodeMoved, parent, parent.getChildCount());
    ((BaseXJTreeModel)this.getModel()).valueForPathChanged(movedPath, xnodeChild);
    e.dropComplete(true);
    } else {
    System.out.println("drop rejected");
    e.rejectDrop();
    } catch (IOException ioe) {
    ioe.printStackTrace();
    } catch (UnsupportedFlavorException ufe) {
    ufe.printStackTrace();
    public void dragEnter(DropTargetDragEvent e) {
    if (isDragOk(e) == false) {
    e.rejectDrag();
    return;
    e.acceptDrag(DnDConstants.ACTION_MOVE);
    public void dragExit(DropTargetEvent e) {
    // Do Nothing.
    public void dragOver(DropTargetDragEvent e) {
    Point dragLocation = e.getLocation();
    TreePath treePath = getPathForLocation(dragLocation.x, dragLocation.y);
    if (isDragOk(e) == false || treePath == null) {
    e.rejectDrag();
    return;
    // Make the node active.
    setSelectionPath(treePath);
    e.acceptDrag(DnDConstants.ACTION_MOVE);
    public void dropActionChanged(DropTargetDragEvent e) {
    if (isDragOk(e) == false) {
    e.rejectDrag();
    return;
    e.acceptDrag(DnDConstants.ACTION_MOVE);
    private boolean isDragOk(DropTargetDragEvent e) {
    /** @todo gestire i casi in cui il drop non sia concesso */
    return (true);
    public void setDragAndDropEnabled(boolean enabled){
    this.DnDEnabled = enabled;
    public boolean isDragAndDropEnabled(){
    return this.DnDEnabled;
    Thanks again.
    flat

  • Passing model reference to a page in a Popup

    Hi all,
    I have a BSP Application with MVC. In a view I want to open a new window when clicking in an input field with a JavaScript function:
    function openCatalog (inputField, inspchar) {
        adresse = "catalog.htm";
        document.formInsertMerkmal.fieldname.value = inputField;
        view = window.open(adresse, "Katalogauswahl", "width=400,height=400,left=100,top=200");
        view.focus();
    The catalog.htm is a bsp page with logic in the same application. Opening and closing this page is no problem.
    But how can I pass the reference to the model from the first view, eg. start.htm to the new page catalog.htm. I want to read data from the model and write data back to model attributes.
    Can I pass the modelreference in the url? And how do I read the model in the new window?
    In start.htm I declared the model in the page attributes and can access data from model.
    What Stepps are necessary to do the same in the new window. I don’t want to raise an event in the controller to go to a next page.
    Please help!

    Hi Raja,
    I just begin to develop with BSP. I don't understand exactly  what I must do :
    "in the method IF_BSP_APPLICATION_EVENTS~ON_START instantiate your model class and pass the instantiate model class reference to a attribute of the application class.
    now this can be referenced in the all the pages with application->applicationclassattribute for model."
    You can do an example source code, please.
    Thanks you very much for help.
    Lionel

  • Passing a reference / variable to a Custom Component

    Hi, I was wondering if someone could help me.
    It seems like a very simple problem but I cant for the life
    of me seem to work out a solution.
    I have created a Custom Component that extends from the
    UIComponent that consists of a “rev counter” style
    clock face etc….
    I want to use this component multiple times within my
    application – however feed it different data so for example
    each “rev counter” on the page will be displaying
    different data etc…..
    I want to be able to reuse my component and not have to
    create a new component every time I add a “rev counter”
    to my application, therefore I need some way of passing a reference
    / variable to the component (maybe from the <mx /> tag where
    I declare it in the MXML code ??? )
    <mx:Application ….
    xmlns:comps="components.*" …..>
    <comps:RevCounterComp id=”” (add something
    here to reference???) />
    </ mx:Application>
    Doing this will allow me to reuse my ONE custom component
    MANY times feeding it different data (different data provaiders for
    each instance of the single component)
    Hope this makes sense???
    Any help / advice is much appreciated,
    Thanks,
    Jon.

    Jon,
    jmryan's suggestion is the preferred way to go. This way you
    can use the simple MXML syntax that you described in your post.
    If your custom component is defined in ActionScript, you can
    use setters or the creationComplete event to update the component
    when the values are passed in from the tag (they are set *after*
    your constructor runs).
    Even easier, if your component is defined in MXML, you can
    add [Bindable] to your public field and then bind directly to it in
    the custom component's MXML code.
    - Peter

  • How to pass file reference to c

    Hi,
    I want to pass file reference pointer to a dll written in visual c++. How can i do that?

    What do you want to do with that reference in your C code? if you want to access it using OS File IO functions you have to be very careful! You should not mix LabVIEW nodes and OS platforms calls together. It's either one or the other.
    If you can guarantee that what you want to do is configure the Call Library Node (CLN) parameter to Adapt To Type. Then right click on the CLN and select "Create C Source Header" or something to that meaning. Save the resulting file to disk. Open it and copy the function prototype into your C/C++ file. There should be a parameter typed LVRefnum *. Now you can use the LabVIEW manager C function MgErr FRefNumToFD(LVRefNum refNum, File *fdp);
    You need to link your DLL with labview.lib in the cintools directory in order to be able to call the FRefNumToFD() function. The value in the fdp reference is the platform specific file handle, so for Windows this is a HANDLE.
    Rolf Kalbermatter
    CIT Engineering Netherlands
    a division of Test & Measurement Solutions

  • Pass by reference and String

    public class Test {
        static void method(String str) {
            str = "String Changed";
        public static void main(String[] args) {
            String str = new String("My String");
            System.out.println(str);
            method(str);
            System.out.println(str);
    }The output is
    My String
    My String
    How this is possible when objects are passed by reference ?

    > How this is possible when objects are passed by reference ?
    All parameters to methods are passed "by value." In other words, values of parameter variables in a method are copies of the values the invoker specified as arguments. If you pass a double to a method, its parameter is a copy of whatever value was being passed as an argument, and the method can change its parameter's value without affecting values in the code that invoked the method. For example:
    class PassByValue {
        public static void main(String[] args) {
            double one = 1.0;
            System.out.println("before: one = " + one);
            halveIt(one);
            System.out.println("after: one = " + one);
        public static void halveIt(double arg) {
            arg /= 2.0;     // divide arg by two
            System.out.println("halved: arg = " + arg);
    }The following output illustrates that the value of arg inside halveIt is divided by two without affecting the value of the variable one in main:before: one = 1.0
    halved: arg = 0.5
    after: one = 1.0You should note that when the parameter is an object reference, the object reference -- not the object itself -- is what is passed "by value." Thus, you can change which object a parameter refers to inside the method without affecting the reference that was passed. But if you change any fields of the object or invoke methods that change the object's state, the object is changed for every part of the program that holds a reference to it. Here is an example to show the distinction:
    class PassRef {
        public static void main(String[] args) {
            Body sirius = new Body("Sirius", null);
            System.out.println("before: " + sirius);
            commonName(sirius);
            System.out.println("after:  " + sirius);
        public static void commonName(Body bodyRef) {
            bodyRef.name = "Dog Star";
            bodyRef = null;
    }This program produces the following output: before: 0 (Sirius)
    after:  0 (Dog Star)Notice that the contents of the object have been modified with a name change, while the variable sirius still refers to the Body object even though the method commonName changed the value of its bodyRef parameter variable to null. This requires some explanation.
    The following diagram shows the state of the variables just after main invokes commonName:
    main()            |              |
        sirius------->| idNum: 0     |
                      | name --------+------>"Sirius"       
    commonName()----->| orbits: null |
        bodyRef       |______________|At this point, the two variables sirius (in main) and bodyRef (in commonName) both refer to the same underlying object. When commonName changes the field bodyRef.name, the name is changed in the underlying object that the two variables share. When commonName changes the value of bodyRef to null, only the value of the bodyRef variable is changed; the value of sirius remains unchanged because the parameter bodyRef is a pass-by-value copy of sirius. Inside the method commonName, all you are changing is the value in the parameter variable bodyRef, just as all you changed in halveIt was the value in the parameter variable arg. If changing bodyRef affected the value of sirius in main, the "after" line would say "null". However, the variable bodyRef in commonName and the variable sirius in main both refer to the same underlying object, so the change made inside commonName is visible through the reference sirius.
    Some people will say incorrectly that objects are passed "by reference." In programming language design, the term pass by reference properly means that when an argument is passed to a function, the invoked function gets a reference to the original value, not a copy of its value. If the function modifies its parameter, the value in the calling code will be changed because the argument and parameter use the same slot in memory. If the Java programming language actually had pass-by-reference parameters, there would be a way to declare halveIt so that the preceding code would modify the value of one, or so that commonName could change the variable sirius to null. This is not possible. The Java programming language does not pass objects by reference; it passes object references by value. Because two copies of the same reference refer to the same actual object, changes made through one reference variable are visible through the other. There is exactly one parameter passing mode -- pass by value -- and that helps keep things simple.
    -- Arnold, K., Gosling J., Holmes D. (2006). The Java� Programming Language Fourth Edition. Boston: Addison-Wesley.
    ~

Maybe you are looking for