07-30-2018 09:21 AM
My advice is "don't get too fancy". The difference in time between "allocating on the fly" and "pre-allocating" was (to my way of thinking) pretty small. If you add a Mod function to the "pre-allocating" code, you make it slower, and wrapping it in a sub-VI (I really like wrapping things in sub-VIs for purposes of hiding the details), you slow it down (another trivial amount) more. One has to ask if "simpler is better", i.e. a For Loop + Indexing Tunnel.
Bob Schor
07-31-2018 09:48 AM
I agree with you Bob. Great that you pointed out that for loop is more time efficient! For purposes of this application it looks like time criticality is not so important (especially comparing to memory management) and even my example would do the job, but keeping good practices since the beginning is really important.
@Wojtek
Have you managed to fix your memory problem?
08-03-2018 02:33 AM
Memory is still continously growing and I see one more thing. Now my DMA buffer have some lag, and gave me always old data from aprox. 2s before
08-03-2018 03:13 AM
Can you post updated version of your application code? Also how do you measure the memory? Option that i would recommend is using NI Distributed System Manager. You can find a guide how to measure memory with this tool in this article: https://knowledge.ni.com/KnowledgeArticleDetails?id=kA00Z000000P9kJSAS.
08-03-2018 04:06 AM
I'm using NI Distributed System Manager.
I've got one more question to you. In my application I'm using lvclass with ctl in which I'm storing data like process controls and 3 data plots. I'm continously putting data to it every loop cycle(example is in attached vi) and showing some of them on main front panel. Can I have memory problem from that? I assume that my lag in data from DMA buffer comes from high CPU usage, am I right?
08-03-2018 08:36 AM - edited 08-03-2018 08:44 AM
To answer your question - it depends. Are you creating new class object every iteration? In that case memory may leak. If not, then it shouldn't occur. Why don't just use Cluster instead of Classes, does your whole application requires you to use Objective Programming? If you have high CPU usage, then definitely it will affect your acquisition and determinism of your application. For information about DMA FIFO behavior you should check them for Overflow and Underflow errors. Please refer to this article for more information: http://zone.ni.com/reference/en-XX/help/371599N-01/lvfpgaconcepts/fpga_dma_fifo_buffer_size/.
08-03-2018 08:48 AM
I'm only using it to have data avalible for the other part of my program. Do you think that changing it to cluster will make my application work better?
Another question is about Queues. Are they dealocating memory? Can they have infuence on my memory problems?
08-03-2018 09:08 AM - edited 08-03-2018 09:22 AM
If you are using Classes properly then everything should be ok. Usage of clusters is just easier. To get more control over memory allocation of your queues you should use RT FIFOs, you can find them in Real-Time palette. The differences between standard queues and RT one you can find in this article http://www.ni.com/product-documentation/54516/en/. But as for the influence on memory problems, although you can check it, it is probably not the main cause. What is the level of cpu usage and memory leak that you encounter? I'm almost sure that somewhere in your code there has to be some iterating memory allocation, that we still cannot find.
I can see that in your Analog_In.vi you are unbundling and then bundling yours data class elements. You can try to do this operation in In Place Element Structure that may increase memory efficiency. http://zone.ni.com/reference/en-XX/help/371361P-01/glang/in_place_element_structure/
08-10-2018 03:14 AM
You were right. In my code I had one element that was continously iterating and when I removed it, everything works fine. Thanks for your help 🙂