Jump to content

Open GDS copy byref object at runtime


Recommended Posts

Copy cannot be auto-generated because your object might contain references and the copy routine has to decide whether to share or clone the references. Mikael’s answer is best. Obviously if the parent class doesn’t have a Clone method, then you cannot add one to the child. 

  • Thanks 1
Link to comment

Thanks MikaelH and Aristos for your answers,

I was rather hoping there would be an easier way around this hence my rather open question, but I can see there are too many caveats for it to be a simple answer. My specific problem involved objects containing other objects as Aristos mentioned (I have a composition). However for this specific case I always want to clone the references. The composition is also built exclusively of items with a shared ancestor. So to do it I have taken the method that MikaelH mentioned, included "call parent method", and replaced the "child" references (i.e. the references in the object's attributes) with copies (recursively to ensure all "descendant" references are copies too).  Thankfully this does the job 🙂

Here is the top level "DeepCopy.vi":

 DeepCopy.png.fe778ac7fe0166d3e230721980f6ec74.png

And the modified MikaelH's method "CopyAttributes.vi" (This method is cloned to all the classes inheriting from TestProfileItem):

CopyAttributes.png.ad2565fab361d6eb6e358458f92e3b1e.png

Many thanks to both of you for your help on this.

Edited by Brains
Link to comment

Someday, I really would like to take two months off of my main dev job to sit down with the developers of some app that uses all this ref stuff and really tear it apart. I've gone through smaller apps and been able to eliminate most of the references, achieving much better performance -- often with a significant decrease in memory and usually fixing a couple of race conditions along the way! But that's only for small apps, which leaves my theory that the big apps would be better off without the ref aspects as just that: a theory. I don't just need my time... I'd also need the time of the large app's developer(s) to provide the handholding to do the analysis. The work I did with Allen Smith on the AF was this weird moment of downtime for me at NI between two major projects, something that doesn't come around often. 

Until that next magical gap in my schedule, I'm just going to look at diagrams like the ones above and wince, whispering quietly, "We gotta find a better way..."

  • Like 1
Link to comment

😄 Thanks Aristos. I find myself in a continual struggle between the light and dark side. I am part of a very small team and one of the main barriers to sticking with byval for us is that the tools for goop based development all seem to prefer byref. While they help to speed up the development process there are always times when a trivial subject for byval such as the above copying process, in byref becomes a complete nightmare. However, for now, the benefits are outweighing the costs.

 

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.