09-15-2008 08:18 AM - edited 09-15-2008 08:20 AM
Hi there!
I've set up a program as follows: after some initialization in the sequence structure (indicated near the bottom) it sticks to the last frame running a perpetual while loop. This loop gets executed roughly twice (due to slow device communication) a second. After a few weeks my vi refuses to exit (i.e. it's stuck on the last sequence frame, displaying the hourglass and only the task manager can kill it; trying to exit it in the first one or two weeks works fine) and hogs the computer (up to the point of it no longer finding c:\). I honestly never grasped the business of reentrant vi's (I'd be grateful for links to some documentation), maybe this is causing my problem? Maybe I'm occupying memory in every pass through the loop by creating a new set of references and property nodes?
Any hint is greatly appreciated!
Regards,
Severin
P.S.: This is using LabView 8.0.1 on Windows XP
09-15-2008
08:25 AM
- last edited on
09-16-2008
11:14 AM
by
Support
Judging by the image you posted....
I would have to first question the "log status every 5 seconds".
Ben
09-15-2008 09:07 AM
Hi Ben!
Thanks for your reply. So you think the problem is not the while loop, but within one of the subvi's I keep calling? If so, I don't think the logging is to blame, since all the other subvi's get called roughly twice a second.
Anyway, to get back on the spot: you don't see anything wrong in my perpetual creating references and property nodes?
Best wishes,
Severin
09-15-2008 09:15 AM
severin wrote:Hi Ben!
Thanks for your reply. So you think the problem is not the while loop, but within one of the subvi's I keep calling? If so, I don't think the logging is to blame, since all the other subvi's get called roughly twice a second.
Anyway, to get back on the spot: you don't see anything wrong in my perpetual creating references and property nodes?
Best wishes,
Severin
Boy you are fast to rule out the most likly suspect.
Use "Tools >>> Profile >>> Performance and Memory" daily to see if memory usage is climbing for any of your sub-VIs.
The control references shown in your screen shot are all static so there should not be a leak in using them.
With the screen shot you shared that is all I can do to hlep you for now.
Ben
09-15-2008 10:28 AM
There is no way for us to troubleshoot an image. We need actual code and all subVIs if possible.
Many features of your code are very inefficient, but they should not lead to a memory leak, still:
I, too, suspect that the problem is in one of your subVIs, but there is no way to tell for sure without doing some profiling.
09-16-2008 03:55 AM
Thanks for the hints, I think I've solved my most pressing problem: indeed the Logging procedure did not (*cough* *cough*) close the file after writing to it. Stupid me. So this might lead to Labview releasing lots of open file handles when exiting. We'll see. Now referring to your points:
* I'll try to get rid of the value properties. However this brings up two questions: what is the difference in speed and memory footprint when comparing wires to local variables? What is the most decent way to pass variables to SubVIs. Whenever I have to edit the variable (or access some Property, like grey out a Front Panel element) I use references - are these any good? In OOP usually it's pretty easy to access the caller's variables, is there something similar in Labview?
* I've cleaned up my time counting. Thanks for pointing out
* I understand the concept of coercion dots, however I don't see how this applies to references. I know I shouldn't wire a U8 to a subVI expecting an I32, but what is the size of a reference? How can they be different, how can I fix them?
* on a related note: What number type does "Open/Create/Replace file" expect? I changed my constant to everything from I8 to U64, but got coercion dots no matter what. The help shows some funny representation like "<>"
* If I'm going to only write properties when they change, don't I have to read them every time to be able to figure out *whether* they've changed? Wouldn't this make the whole process just as expensive? Or did you imply it's faster to keep a copy of my property in a separate U8?
Regards,
Severin
09-16-2008 04:18 AM
severin wrote:
[...]
a) I'll try to get rid of the value properties. However this brings up two questions: what is the difference in speed and memory footprint when comparing wires to local variables? What is the most decent way to pass variables to SubVIs. Whenever I have to edit the variable (or access some Property, like grey out a Front Panel element) I use references - are these any good? In OOP usually it's pretty easy to access the caller's variables, is there something similar in Labview?
[...]b) I understand the concept of coercion dots, however I don't see how this applies to references. I know I shouldn't wire a U8 to a subVI expecting an I32, but what is the size of a reference? How can they be different, how can I fix them?
c) on a related note: What number type does "Open/Create/Replace file" expect? I changed my constant to everything from I8 to U64, but got coercion dots no matter what. The help shows some funny representation like "<>"
[...]
Regards,
Severin
I changed some of the stars of your list to a), b) and c) in order to answer.
a) You have to use references if you want to change properties of the fp-element during runtime (e.g. disable). There is no way around that, but you still can waste performance if working bad with this mechanics. There is only one property which should not be adressed using references: the value. The best thing is to use wires (speed and memory), then use variables (speed) then use property nodes (see here).
b) References can be 'typified'. There are three "states" of references: not typified, typified and strict typified. Connecting e.g. a typified reference to a strict typified reference will create a coercion dot. Use "to more specific class" and "to more generic class" to cast references as needed.
c) The input is a typified enum. Best thing you can do: rightclick the connector and select: create constant/control.
just some hints,
Norbert
09-16-2008 11:07 AM - edited 09-16-2008 11:08 AM
Yes, not closing the file references was probably your main problem. All other issues are more cosmetic than anything else and only
really need to be addressed if you have performance or memory problems. Still, I always recommend clean and stremlined code. 🙂
There was no way for us to point ot the file problem, because it was not visible in your code. Do you always write to the same file?
In this case you would open the file once before the loop, keep it open during the loop, append data as needed, and close the file once the loop finishes.
severin wrote:* on a related note: What number type does "Open/Create/Replace file" expect? I changed my constant to everything from I8 to U64,
but got coercion dots no matter what. The help shows some funny representation like "<>"
The easiest way to get the correct type is always to right-click the terminal and select "create constant|indicator|control" as needed.
You did not say which input you mean, but both the "operation" and "access" inputs are enums. Use enums instead of numerics to
make the code much easier to read. Who wants to constantly query the help pages or memorize the mappings to numbers? 🙂
severin wrote:* If I'm going to only write properties when they change, don't I have to read them every time to be able to figure out *whether* they've
changed? Wouldn't this make the whole process just as expensive?
No, checking for a change is trivially cheap compared to a property node. In newer LabVIEW versions you would use a globally initialized feedback
node and a simple "not equal" comparison of the current and previous value to see if the value has changed. If I remember right, there is also an openg tool for this.