LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

memory management in labview as C language

Hi,

 

i have understood the memory management in C program. It has code memory , data memory, stack and heap memory. All locals will store in stack, global in data memory , dynamic memory allocation in heap and code in code memory.

 

Is it the same memory allocation concept applies to Labview. If not how it differs. Please explain with examples. 

 

Regards,

Anand

0 Kudos
Message 1 of 7
(3,947 Views)

Hi Anand, are you working with very large data sets or low-performance machine? If not, I'd say don't worry about the memory management unless you are having issues. There are some times when you will want to use the in place element structure in order to avoid memory copies. You can use the profile tools to show buffer allocations, which is each time memory is going to be set aside to hold the contents of a wire, but this is usually not necessary. 

 

It is often good to pre-allocate an array if you can, and use for loops whenever possible instead of while loops. But beyond this it is very easy to fall into the weeds!

0 Kudos
Message 2 of 7
(3,938 Views)

As stated above, in LabVIEW you generally do not need to worry about memory management. LabVIEW handles that for you. There are things you can do to improve performance and to give hints to the compiler and runtime engine how to handle memory to avoid unnecessary copies of data. Generally though unless you are dealing with large amounts of data you don't need to be concerned.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 3 of 7
(3,923 Views)

LabVIEW will do the memory management for you automatically.

 

To limit memory use, you need to write the code in a way to limit buffer allocations (e.g. array resizing), limiting data duplication, and optimize for inplaceness. Often, the LabVIEW compiler can optimized the code even of you don't write it in the best way. It is very smart!

 

For some ideas, have a look at our old NI-WEEK presentation.

 

In summary, you don't have direct acccess to the memory management, but you can write your code in a way to be optimized for e.g. small size or high performance, or sometimes even both.

0 Kudos
Message 4 of 7
(3,918 Views)

@AnandR wrote:

Hi,

 

i have understood the memory management in C program. It has code memory , data memory, stack and heap memory. All locals will store in stack, global in data memory , dynamic memory allocation in heap and code in code memory.

 

Is it the same memory allocation concept applies to Labview. If not how it differs. Please explain with examples. 

 

Regards,

Anand


As others have said we do not need to concern ourselves with the details of memory in LabVIEW because it takes are of all of those details for us.

 

So your question read a lot like...

 

"

i have understood the operation of a horse and buggy.. It has code Hoofs legs a back and a head.. .

 

Is it the same operation as driving a truck? If not how it differs. Please explain with examples. 

"

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 5 of 7
(3,894 Views)

Thanks to all for the replies. As you all mention , i can leave the memory management to labview compiler. But few concepts in labview made me to ask further question. pls read below.

 

Labview also has the concept of local variables and global variables . Where these variables stored.Can i get any .map files to read the memory location after labview compiled the source code. Is the labview compiler also follows the C compilation like, compilation, assembling,linking.

 

        And also when i referring some CLAD questions i came across a questions like what memory used for front panel(i am not clear on question) and answer is like code and data memory. what does this mean.

 

 

Regards,

Anand

0 Kudos
Message 6 of 7
(3,862 Views)

You seem to be coming from an embedded development word. .map files have long lost any meaningfulness in modern operating systems. Nowadays the created code is fully relocatable (another word used is position independent code (PIC)) and the operating system does not anymore load code into a well known address space but rather does address randomization when loading code modules in order to make it more difficult for rogue code to locate known vulnerabilities to exploit.

LabVIEW did that actually more or less from the start as the compiled binary code of every VI is linked together at VI load time in memory. It wasn't true randomization to begin with but it had pretty much the same effect as even small variations in the compiled code of one of the used VIs would generally change the memory layout of the loaded and linked code considerably.

If you really want to read more about the internal workings of LabVIEW you can read this where a LabVIEW developer explains in more detail about the inner workings from going from a VI diagram, to a so called DFIR directed graph representation of the code where LabVIEW then does all kinds of transforms on that for high level optimization and after that everything gets send to the LLVM compiler to create the actual target code. While the general principle is similar to a C compiler many of the intermediate steps are pretty different and except for the LabVIEW developers themselves there is no real way to get at the intermediate steps of this process.

 

As to your last question a compiler basically distinguishes between data space and code space also commonly called data segment and code segments on the x86 architecture. The difference is that while data segments are setup to be both readable and writeable code segments are setup to be only readable after they have been initialized.

The reason is obvious. You do not want some rogue code to be able to change your compiled code at runtime to execute something bad. By setting the memory segment in which the code is loaded to be read only, any attempt to modify that code by whomever will cause a protection fault and shutdown your process for good. Data space however needs to be modifiable. The frontpanel can be modified by changing the size, color and values of the controls and the frontpanel itself. If the memory where the frontpanel is loaded would be read only such attempts would shutdown your process.

Basically you need to know that variables are stored in data space while the compiled code (and sometimes constant declared variables) are stored in the code space. And while I'm not sure LabVIEW even can make code segments read only (generally that is an operation only the kernel itself can do during loading of EXE or DLL modules since it involves changing hardware registers in the memory management unit that are protected themselves from being modified by anyone but ring 0 code) it still distinguishes data and code space.

 

Well reading a bit further on MSDN you can't execute code in memory that is allocated with HeapAlloc() in Windows. To get such memory one must use VirtualAlloc() and that function allows to specify if the allocated memory area should be write protected. So I'm pretty sure LabVIEW loads its compiled code into write protected memory buffers too.

Rolf Kalbermatter
My Blog
Message 7 of 7
(3,842 Views)