LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

re-init object or class inside a DVR without creating a new class

Hello,

 

I am struggling with something here, I need to be able to create a blank object to reinitialise my data back to its original blank values, (ie. think of it a reinitialising my cluster to blank values if I have the terminology wrong). I was wandering how I would do it. I am currently inside a Data value refence node for memory purposes and I need it to re-initialise the data. I have attached a code snippet but the VI says error saying "the object inside a reference canneot be exchanged with another object... I don't want to exchange it, I would like to reinitialise it.


Any ideas? Snippet attached.


Thanks


Pete

0 Kudos
Message 1 of 6
(3,275 Views)

If you look at the additional details section of the error window, it should tell you that LV doesn't allow this because it insists on having the exact same type entering and leaving the structure. When you have an object, the object may have the same wire type, but the actual object on the wire may be an unrelated decendant and thus have a completely different representation in memory.

 

The solution is to use the Preserve Run-Time Class primitive, which performs an operation which can be difficult to understand, so you probably want to read the documentation carefully. Basically, you want to wire your constant into the left terminal and the output of the IN DVR node into the top terminal and wire the result into the OUT DVR node. This will guarantee that the type on the wire at run-time is compatible with what's in the DVR (or if it isn't, will output an error and a default value which does match), which is what the structure demands.


___________________
Try to take over the world!
0 Kudos
Message 2 of 6
(3,272 Views)

Hello,

Ok that makes sense, what I am actually looking for is a quick way to blank out all the data which the reference is pointing at. Ie. it is curerntly full with several 2D arrays that I would like to be put back to blank arrays. So I am just looking for a quick way of doing it without having to go into every single instance and write a blank value to it and come back again if that is possible? I defiitely want it to blank the same memory space as the reference is pointing at.


Thanks

Peter

0 Kudos
Message 3 of 6
(3,263 Views)

There's a limit to how much you can control exactly which area of memory LV uses for storage of specific data.

 

You seem to think that you have a problem with memory consumption (you said it and I see you have a request deallocation primitive in your code, which probably doesn't do what you want). This is usually an indication of code that needs to be changed. If you are actually having memory problems (and you might not be), then the usual sources are either creating multiple copies of large arrays or allocating large arrays (since they require contiguous space, although this is less of an issue with string arrays, because the data in the actual array is only a pointer).

 

If this is really your problem, I would suggest that you start a new thread which indicates that's the problem and upload your code there so that people have something real to work with. Otherwise, the method I outlined in the previous post will replace the element in the DVR with an empty one, but I don't think that will help you, because I think your actual problem is elsewhere.


___________________
Try to take over the world!
0 Kudos
Message 4 of 6
(3,246 Views)

Implement a "Delete data" method for your classes.  You should never have to know about the internals of your data (outside the class boundary) to perform actions like this.

 

Shane.

Message 5 of 6
(3,194 Views)

@Intaris wrote:

Implement a "Delete data" method for your classes.  You should never have to know about the internals of your data (outside the class boundary) to perform actions like this.

 

Shane.


Exactly, and the function is dead simple, just write an empty class cluster to the memory.

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 6 of 6
(3,188 Views)