Hey people,
I've been reading up on efficient memory usage in this forum and the
tutorials, especially with respect to arrays, since I'm using a few
boolean arrays in my current project. I have some questions regarding
this.
In my program (which is to be embedded into a FieldPoint controller) I
have three parallel while loops. One of the loops regularly updates the
value of 2 arrays (one of 8 boolean values, one of 16 boolean values)
based on the values of a couple of controls, in other words, the
'logic' part of my VI. Another loop is responsible for accessing a
DataSocket server in order to obtain the values based on which the
arrays will be updated, while also writing the values contained within
the arrays to the DataSocket server. The third is responsible for
actually outputting the values contained within the arrays to the
FieldPoint controller.
My question has to do with how copies of an array affect memory usage.
From my readings so far it seems that pre-allocation of an array of
constant size (my arrays do not resize) will reduce the amount of
memory usage, as well as the usage of a shift register to pass the
values of the array from one iteration of a while loop to the next, in
place of using a local variable. However, for my 2nd and 3rd loops,
both of which require the values of the arrays for output to either the
DataSocket server or the FieldPoint controller, I am currently using
local variables of the arrays to pass these values, and it works fine
when the program is run on a desktop with 1 GB of RAM. However, since
the FieldPoint unit only has 8 MB of DRAM, I would like to know how
exactly these local variables affect my overall program's memory usage.
Will each local variable make a new copy of the array for every
iteration of the loop it resides in, filling up the memory totally? Or
will each local variable reserve an array in the RAM for itself (since
it is of constant size) which it will then use for every iteration?
If I'm using a shift register for the first loop and the output of the
left-side shift register is wired to two blocks (one Index Array to
extract the values and one Replace Array Subset to replace the values
after completion of the program logic) will this generate 2 copies of
the array in memory? Will each new iteration then reserve a new slot in
the memory for the new arrays?
I have read a few of the forum posts on related topics, and also referred to this tutorial
http://zone.ni.com/devzone/conceptd.nsf/webmain/732cec772aa4fbe586256a37005541d3
Thanks for the help!