Avoiding data memory duplication in subVI calls

Hi,
I am on a Quest to better understand some of the subtle ways of the LabVIEW memory manager. Overall, I want to (as much as practically possible) eliminate calls to the memory manager while the code is running.
(I mainly do RT code that is expected to run "forever", the more static and "quiet" the memory manager activity is, the faster and simpler it is to prove beyond reasonable doubt that your application does not have memory leaks, and that if will not run into memory fragmentation (out of memory) issues etc. What I like to see as much as possible, are near static "used memory" and "largest contiguous block available" stats over days and weeks of deployed RT code.)
In my first example (attached, "IPE vs non-IPE.png"), I compared IPE buffer allocation (black dots) for doing some of the operations in an IPE structure vs. "the old way". I see fewer dots the old way, and removed the IPE structure.
Next I went from initializing an array of size x to values y to using a constant array (0 values) with an "array add" to get an array with the same values as my first version of the code. ("constant array.png")
The length of the constant array is set to my "worst case" of 25 elements (in example). Since "replace sub-array" does not change the size of the input array even when the sub-array is "too long", this saves me from constantly creating small, variable sized arrays at run-time. (not sure what the run-time cpu/memory hit is if you tried to replace the last 4 elements with a sub-array that is 25 elements long...??)
Once I arrived at this point, I found myself wondering "how exactly the constant array is handled during run-time?". Is it allocated the first time that this sub-vi is called then remains in memory until the main/top VI terminates, or is it unloaded every time the SubVI finishes execution? (I -think- Mac's could unload, while windows and linux/unix it remains in memory until top level closes?)  When thinking (and hopefully answering),  consider that the the code is compiled to an RTEXE runningg on a cRIO-9014 (vxWorks OS).  
In this case, I could make the constant array a control, and place the constant on the diagram of the caller, and pipe the constant all the way up to the top level VI, but this seems cumbersome and I'm not convinced that the compiler would properly reckognize that at the end of a long chain of sub-sub-sub VI's all those "controls" are actually always tied off to a single constant. Another way would perhaps be to initialize a FG with this constant array and always "read it" out from the FG. (using this cool trick on creating large arrays on a shift register with only one copy which avoids the dual copy (one for shift register, one from "initialize array" function)).
This is just one example of many cases where I'm trying to avoid creating memory manager activity by making LabVIEW assign memory space once, then only operate on that data "in-place" as much as possible. In another discussion on "in-place element" structures (here), I got the distinct sense that in-place very rarely adds any advantage as the compiler can pick up on and do "in-place" automatically in pretty much any situation. I find the NI documentation on IPE's lacking in that it doesn't really show good examples of when it works and when it doesn't. In particular, this already great article would vastly benefit from updates showing good/bad use of IPE's.
I've read the following NI links to try and self-help (all links should open in new window/tab):
cool trick on creating large arrays on a shift register with only one copy
somewhat dated but good article on memory optimization
IPE caveats and recommendations
How Can I Optimize the Memory Use in My LabVIEW VI?
Determining When and Where LabVIEW Allocates a New Buffer
I do have the memory profiler tool, but it shows min/max/average allocations, it doesn't really tell me (or I don't know how to read it properly) how many times blocks are allocated or re-allocated.
Thanks, and I hope to build on this thread with other examples and at the end of the thread, hopefully everyone have found one or two neat things that they can use to memory optimize their own applications.  Next on my list are probably handling of large strings, lots of array math operations on various input arrays to create a result output array etc.
-Q
QFang
CLD LabVIEW 7.1 to 2013
Attachments:
IPE vs non-IPE.png ‏4 KB
constant array.png ‏3 KB

I sense a hint of frustration on your part, I'm not trying to be dense or difficult, but do realize that this is more towards the "philosophical" side than "practical" side. Code clarity and practicalities are not necessarily the objectives here.
Also, I have greatly appreciated all your time and input on this and the other thread!
The answer to your first question is actually "yes, sort of". I had a RT application that developed a small memory leak (through a bug with the "get volume info.vi' from NI), but to isolate it and prove it out took a very long time because the constant large allocation/deallocations would mask out the leak. (Trace's didn't work out either since it was a very very slow leak and the traces would bomb out before showing anythinng conclusive.) The leak is a few bytes, but in addition to short term memory oscilations and  long term (days) cyclical "saw-tooth" ramps in memory usage, made this very hard to see. A more "static" memory landscape would possibly have made this simpler to narrow down and diagnose. or maybe not. 
Also, you are missing my point entierely, this is not about "running out of memory" (and the size of 25 in my screen-shot may or may not be what that array (and others) end up being). This is about having things allocated in memory ONCE then not de-allocated or moved, and how/when this is possible to accomplish.  Also this is a quest (meaning something  I'm undertaking to improve and expand my knowledge, who said it has to be practical).
You may find this document really interesting, its the sort of thing you could end up being forced to code to, albeit, I don't see how 100% compliance with this document would ever be possible in LabVIEW, thats not to say its worthless: JPL Institutional Coding Standard for the C Programming Language (while it is directed at C, they have a lot of valid general points in there.)
Yes, you are right that the IPE would grow the output if the lenght of my replacement array is not the same, and since I can't share the full VI's its a bit of a stretch to expect people to infer from the small screen dummp that the I32 wires on the right guarantee the lengths will match up in the IPE example.
Once, on recomendation of NI support, I actually did use the Request deallocation primitive during the hunt for what was going on in that RT app I was debugging last year. At that particular time, the symptom was constant fragmentation of memory, until the largest contiguous block would be less than a couple of kB and the app would terminate with 60+MB of free memory space.. (AKA memory leak, though we could not yet prove that from diagnostic memory consumption statistics due to the constant dynamic behavior of the program)  I later removed them. Also, they would run counter to my goal of "allocate once, re-use forever" that I'm chasing. and again, I'm chasing this more as a way to learn than because all my code MUST run this way. 
I'm not sure I see what you mean by "copying data in and out of some temporary array". Previously (before the constant array) at every call to the containing sub-vi, I used to "initialize array" with x elements of value y (where x depends to a large degree on a configuration parameter, and y is determined by the input data array). Since I would call to "initialize" a new array each time the code was called, and the size of the array could change, I looked for a way that I could get rid of the dynamic size, and get rid of dynamically creating the array from scratch each time the sub-vi was called. What I came up with is perhaps not as clear as the old way I did it, but with some comments, I think its clear enough. In the new way, the array is created as a constant, so I would think that would cause less "movement" in memory as it at that point should be preventing the "source" array from (potentially) moving around in memory?  Considering the alternative of always re-creating a new array, how is this adding an "extra" copy that creating new ones would not create?
How would you accomplish the task of creating an array of "n" elements, all of value "y" without creating "extra" copies? -auto-indexing using a for loop is certainly a good option, but again, is that sure to reuse the same memory location with each call? Would that not, in a nit-picking way, use more CPU cycles since you are building the array one element at the time instead of just using a primitive array add operation (which I have found to be wicked fast operations) and operate on a constant data structure?
I cannot provide full VI's without further isolation, maybe down the road (once my weekends clear up a bit). Again, I appreciate your attention and your time!
QFang
CLD LabVIEW 7.1 to 2013

Similar Messages

  • How to free persistent data memory?

    Hi,
    Recently I have been working on card applet developing.In my applet I want to use EEPROM to hold a large file, so I apply byte array[] in class constructor.
    In Write method I write data to the byte array[]; In Delete method I want to make the byte array[] null,so I used "byte array[] = null".
    When I test it in emluator it works well, the data I wrote in the byte array can be removed. But when I test it in the real card, if I want to delete the file (equals with making the byte array null) I always got the error.
    So I want to know how to free persistent data memory, dos "= null"work?
    Thanks

    Java Cards are not required to support automatic garbage collection, although some do.
    On Java Card there is a feature called object deletion which can be implemented as garbage collection but can also be implemented differently. Please read the related section in the Java Card Runtime Environment Specification.
    With
    javacard.framework.JCSystem.isObjectDeletionSupported()
    you can check if object deletion is supported on your card.
    With
    javacard.framework.JCSystem.requestObjectDeletion()
    you can request it for the next call of the process method.
    And don't forget to clear all your references to the object which is to be deleted.

  • How can I display data gathered in a subVI in a graph of the main VI?

    I have written a largish application (~50 VI's) which acquires, analyzes, display and saves data from an instrument with a built-in DAQPad. My problem is that my block diagram is rather messy by now. I'm using an event structure in my main VI which reacts to buttons being pressed on the front panel. During data acquisition (one frame of the event structure), I need to do a lot of data processing, and I'm displaying both raw data and analyzed data on the front panel. I'm using a lot of subVI's for this, but I always need to get data out of the subVI's again to display it on the front panel, cluttering my block diagram. It would be much nicer if the subVI could update the main VI's graphs and indicators. I just found two examples with control references which show how a subVI can modify e.g. a 3Dgraph of the main VI, but I'm unable to use this with normal graphs and charts - I can't find a way to update the actual data in the plots (I can scale the plot or color it blue etc - but I really want to change the data it's displaying, not color it blue). Is there anything I'm missing? Is there example code for this kind of problem?
    best regards
    Martin

    im assuming that you want to update your graphs and indicators as you are performing your DAQ, otherwise, you can pass out your value/s when the DAQ completes.
    I have attached a very simple example of using a reference to update your front panel graph.
    Hope this helps.
    Attachments:
    Reference Example(LV7.1).zip ‏17 KB

  • How to get the size of physical memory by using system call ?

    how to get the size of physical memory by using system call ?What system call can be used for me to get the size of physical memor? thanks.

    %vmstat 3
    procs memory page disk faults cpu
    r b w swap free re mf pi po fr de sr s0 -- -- -- in sy cs us sy id
    0 0 0 3025816 994456 4 19 6 0 0 0 0 8 0 0 0 459 253 139 1 1 99
    0 0 0 2864688 777408 0 2 0 0 0 0 0 3 0 0 0 428 134 175 0 1 99
    0 0 0 2864688 777408 0 0 0 0 0 0 0 7 0 0 0 448 112 166 0 0 100
    one interesting observation about vmstat I found out is (mostly on Solaris)
    the first line of information always off chart, so I usually do a few interval to get constant result.
    if you use linux
    just
    cat /proc/meminfo

  • Date/Time Format Stored Procedure Calls in ADVANCE MODE in JDBC ADAPTER

    Hi Experts,
    What is significance of Date/Time Format Stored Procedure Calls in ADVANCE MODE in JDBC ADAPTER.
    Thanks,
    ABDUR

    I guess this would be applicable for the folowing formats - DATE, TIME, TIMESTAMP.
    This is the correct link
    http://help.sap.com/saphelp_nw04/helpdata/en/64/ce4e886334ec4ea7c2712e11cc567c/content.htm
    Regards,
    Prateek

  • Labview 8.5.1's MathScript window failed running imread with an error "A problem occurred in a subVI call."

    Hi,
    I am trying to port a Matlab program into a MathScript script.  Following is the first few lines of the script:
    clear;
    image1=imread('C:\LV_VertAlign\DSC_0104.jpg','jpg');
    image_double1=im2double(image1);
    image_gray11=rgb2gray(image_double1);
    In the first line, imread is supposed to read in a photo taken from a DSLR camera, so I think it's a 32-bit image.  And this is the error I got when trying to run this script in the Labview 8.5.1's Mathscript windows:
    "Error in function imread at line 2.  A problem occurred in a subVI call."
    What is the problem here?  and why does it complain about a subVI call?
    Thanks for any help to point me in the right direction.
    -Anh

    Hello Anh,
    As you may know, LabVIEW MathScript is implemented on top of LabVIEW.  The error message you received indicates that a problem occurred in one of the LabVIEW subVIs that MathScript calls.  As Jim indicated, the problem is in the file type specifier you passed to the function.  MathScript requires the use of 'JPEG' and not 'jpg' or even 'jpeg.'  In this case, we could return a better error message.  I have filed a bug report (115804) for this issue.
    You will find that once you fix this, the im2double and rgb2gray functions are not supported.  In LabVIEW MathScript, you generally can execute scripts written in the MATLAB® language syntax.  However, the MathScript engine executes the scripts, and the MathScript engine does not support some functions that the MATLAB software supports.
    We will look into adding these functions in a future release of LabVIEW MathScript.  If you need this functionality now, these functions are very simple to write yourself.  If you are performing additional image analysis in your script, you may wish to purchase the IMAQ toolkit.  It doesn't add any functions to MathScript at this time, but you could continue your analysis outside of MathScript with LabVIEW VIs.
    MATLAB® is a registered trademark of The MathWorks, Inc.
    Grant M.
    Staff Software Engineer | LabVIEW Math & Signal Processing | National Instruments

  • Is it possible to take the CDR data from a v4.2 Call Manager and copy it to a separate server where it would be made available for reporting?

    Is it possible to take the CDR data from a v4.2 Call Manager and copy it to a separate server where it would be made available for reporting? We are not interested in migrating the CDR data to v6 because of the concerns it introduces to the upgrade process. Is it possible to get the raw data and somehow serve it from a different machine? (knowing it would be 'old' data that stops as of a certain date). If so, what would be the complexity involved in doing so?
    It seems like the CDR data lives within MSSQL and the reporting interface is within the web server portion of the Call Manager... that's as far as we've dug so far.

    Hi
    It is absolutely possible to get the data - anyone you have in your org with basic SQL skills can move the data off to a standalone SQL server. This could be done most simply by backing up and restoring the DB using SQL Enterprise Manager.
    Moving the CAR/ART reporting tool would be more difficult... if you do actually use that for reporting (most people find it doesn't do what they need and don't use it for anything but basic troubleshooting, and get a third party package) then the best option may be to keep your publisher (possibly assigning it a new IP) and leave it running for as long as you need reporting.
    You would then need a new server to run your upgraded V6 CCM; you may find you need this anyway.
    Regards
    Aaron
    Please rate helpful posts...

  • ORA-00932: inconsistent datatypes: expected DATE got NUMBER at OCI call OCIStmtExecute in OBIEE 11g

    Hi Friends,
    I am getting this error : ORA-00932: inconsistent datatypes: expected DATE got NUMBER at OCI call OCIStmtExecute when I am trying to put the filter condition on the date column.
    "Dim-Time"."Day" <= cast(MAX("Dim-Time"."Day") as date)  and "Dim-Time"."Day" >= TIMESTAMPADD(SQL_TSI_MONTH, -1,cast(MAX("Dim-Time"."Day") as date).
    I have casted the max date but though I am getting the above error. I am thinking max(date) is creating the problem.
    Please suggest your on opinion this.
    Thanks.

    Not sure why you need cast in your statement if at all it is required then you need to do as below
    cast("Dim-Time"."Day"  as date)<= cast(MAX("Dim-Time"."Day") as date)  and cast("Dim-Time"."Day"  as date) >= TIMESTAMPADD(SQL_TSI_MONTH, -1,cast(MAX("Dim-Time"."Day") as date).
    ~ http://cool-bi.com

  • The incoming tabular data stream (TDS) remote procedure call (RPC) protocol stream is incorrect. Too many parameters were provided in this RPC request. The maximum is 2100

    Hello,
    I am getting a new message this morning creating a view:
    The incoming tabular data stream (TDS) remote procedure call (RPC) protocol stream is incorrect. Too many parameters were provided in this RPC request. The maximum is 2100
    Any ideas on this?
    Thanks,
    DOm
    System Center Operations Manager 2007 / System Center Configuration Manager 2007 R2 / Forefront Client Security / Forefront Identity Manager

    Hi,
    Based on my research, this is a limitation of sql server.
    http://msdn.microsoft.com/en-us/library/ms143432.aspx
    And please refer to the below article to find a fix for this issue:
    How to fix SQL error: "Too many parameters were provided in this RPC request"
    http://blogs.msdn.com/b/emeadaxsupport/archive/2009/09/01/how-to-fix-sql-error-too-many-parameters-were-provided-in-this-rpc-request.aspx
    Regards,
    Yan Li
    Regards, Yan Li

  • How can i know the data that labview takes when calls visa read?????????????

    First sorry for my english!
    I have a program in wich i read data trough USB(in bulk mode) from a FIFO(from a microprocesor) . I don´t know if when i do a visa read and the program that is running in my microprocessor is waiting for the FIFO full, what data catch the visa read?, because labview don´t wait, always take data when visa read is call!!
    THANKS THANKS......

    A read operation just retrieves the bytes that are available on the serial port. Means that these bytes are there because they have already been sent by the connected device. They may be remains from a previous communication.
    Your protocol should ensure that
    1/ the serial buffer is empty before your start your communication session.
    2/ you read either a specified number of bytes, or all the incoming bytes, using a timeout in case of failure
    3/ you leave things clean after communication (empty buffer, close port...).
    Try to be e more specific if you need further help.
    Chilly Charly    (aka CC)
             E-List Master - Kudos glutton - Press the yellow button on the left...        

  • How to get physical memory by using system call ?

    how to get physical memory by using system call ?What system call can I use.thanks

    Use sysconf(3C) with SCPHYS_PAGES

  • Why data memory is not completely wiped out while closing a VI?

    I am facing some memory allocation issue in my LabVIEW project. Help me sorting it out. Followed below steps,
    1. Launching LabVIEW 2011.
    2. Checking memory allocation (say it is n kB) 3. Opening my project VI.
    4. Again checking memory allocation (say it is n + 10 kB) 5. Closing the VI.
    6. Again checking memory allocation.
    7. Expected it to be n KB. But it is not. There is some residual memory which is not properly wiped out.
    8. Repeated these same steps for NI example VI (C:\Program Files\National Instruments\LabVIEW 2011\examples\control\PID\Autotuning PID Online with Gain
    Scheduling.vi) found same results.
    Explain me why the data memory allocated while opening the VI is not completely wiped out after closing it.
    We are doing some memeory optimization in our LabVIEW project. So a clear justification is required for this question.
    Thanks,
    Rameshkannan

    mrk1 wrote:
    I am facing some memory allocation issue in my LabVIEW project. Help me sorting it out. Followed below steps,
    1. Launching LabVIEW 2011.
    2. Checking memory allocation (say it is n kB) 3. Opening my project VI.
    4. Again checking memory allocation (say it is n + 10 kB) 5. Closing the VI.
    6. Again checking memory allocation.
    7. Expected it to be n KB. But it is not. There is some residual memory which is not properly wiped out.
    8. Repeated these same steps for NI example VI (C:\Program Files\National Instruments\LabVIEW 2011\examples\control\PID\Autotuning PID Online with Gain
    Scheduling.vi) found same results.
    Explain me why the data memory allocated while opening the VI is not completely wiped out after closing it.
    We are doing some memeory optimization in our LabVIEW project. So a clear justification is required for this question.
    Thanks,
    Rameshkannan
    YOu may be seeing the file alloaction info being cached. LV will try to remeber where it found files so it can find them faster next time.
    I suspect you should ignore that part and focus on the parts of your code that is suffering from memory abuse.
    You can use the Profile VIs tools to locate who is gobling up the memory.
    Then use "show buffer allocations" to figure out where the issue is.
    Post image if you want the gang here to "play along".
    Ben
    Ben Rayner
    I am currently active on.. MainStream Preppers
    Rayner's Ridge is under construction

  • How to avoid data repetation when using select statements with innerjoin

    how to avoid data repetation when using select statements with innerjoin.
    thanks in advance,
    satheesh

    you can use a query like this...
      SELECT DISTINCT
             frg~prc_group1                  "Product Group 1
             frg~prc_group2                  "Product Group 2
             frg~prc_group3                  "Product Group 3
             frg~prc_group4                  "Product Group 4
             frg~prc_group5                  "Product Group 5
             prc~product_id                  "Product ID
             txt~short_text                  "Product Description
    UP TO 10 ROWS
    INTO TABLE l_i_data
    FROM
    Joining CRMM_PR_SALESG and
    COMM_PR_FRG_ROD
    crmm_pr_salesg AS frg
    INNER JOIN comm_pr_frg_rod AS prd
    ON frgfrg_guid = prdfragment_guid
    Joining COMM_PRODUCT and
    COMM_PR_FRG_ROD
    INNER JOIN comm_product AS prc
    ON prdproduct_guid = prcproduct_guid
    Joining COMM_PRSHTEXT and
    COMM_PR_FRG_ROD
    INNER JOIN comm_prshtext AS txt
    ON prdproduct_guid = txtproduct_guid
    WHERE frg~prc_group1 IN r_zprc_group1
       AND frg~prc_group2 IN r_zprc_group2
       AND frg~prc_group3 IN r_zprc_group3
       AND frg~prc_group4 IN r_zprc_group4
       AND frg~prc_group5 IN r_zprc_group5.
    reward it it helps
    Edited by: Apan Kumar Motilal on Jun 24, 2008 1:57 PM

  • Carrier data update failure and droping calls continously

    This issue with my new iphone 4s with only 1 carrier not all
    carrier data update failure and droping calls continously & bad quality.my carrier which is ZAIN TELECOM/Iraq that not resolved with restore

    After managed to keep my Z10 running again, it informed me, that there was a new update available, released at 6:38pm with 88MB.
    I installed it, hoping that it would terminate the problems I mentioned in my initial post...and:
    I can now JOIN THIS PROBLEM FRACTION:
    http://supportforums.blackberry.com/t5/BlackBerry-Z10/Just-updated-to-latest-OS-and-phone-is-frozen-...
    WHAT THE F IS WRONG WITH YOU PEOPLE????
    I AM THAT CLOSE, SMASHING THAT DEVICE WITH A SLEDGEHAMMER!
    Did I mention, that I normally charge my customers with 2.500€ a day, when they order my services as a communication consultant and that I do most of my business when I am mobile and traveling?
    Due to Your sloppy work, I already "lost" a day, where I was not available and I did not get any kind of answer of You guys til know... Maybe I´ll should charge BlackBerry for each and every hour that I am "out of business" caused by Your work...

  • Data memory erasure

    How do I erase the data memory from the C7280 printer.  I want to get rid of the printer.

    The C7280 does not have a hard drive or other memory that stores information on what is printed, it will forget all this as soon as the power is removed.  It does have a FAX log that stores information on what numbers have sent you faxes as well as your FAX setup information.  This information can be erased by performing a semi-reset as shown in Solution Ten of the page here.  Using # and 6 when performing the reset will perform a more thorough reset.
    Bob Headrick,  HP Expert
    I am not an employee of HP, I am a volunteer posting here on my own time.
    If your problem is solved please click the "Accept as Solution" button ------------V
    If my answer was helpful please click the "Thumbs Up" to say "Thank You"--V

Maybe you are looking for

  • Print Dialog Box from Report

    Can we open a Print dialog box ( as the one which opens from File->Print in MS Word document) which list all the configured Printers from an Oracle Report (9i/10G) deployed in web environment running on OAS. Thanks in Advance.

  • Cacaoadm  solaris 10 x86 123896-20 patch

    Hi all. i have to install and add 123896-20 x86 solaris 10 cacaoadm patch. but i have sun online records and last 3 days sunsolve.sun.com site is not permit patch download. probably this is oracle mission anyone have this patch software. please give

  • Error reconciling AD Lookups OIM 11g IBM JDK 6 64 bit

    Hi, I'm setting up SSL from OIM 11g to AD 2008, my environment is OIM 11g+ Weblogic 10.3.3 generic on IBM AIX 6.1 + IBM JDK 6 64 bit. I imported the certificate as described in AD connector documentation with "keytool". I'm getting the following ERRO

  • REP-0108 Error

    I installed Developer 6.0 form, graph, report runtime on a client machine and now I get REP-0108: file 'rwbdexpg' not found errors. The help says to make sure the report30 path is correct. Doing a find on the machine comes back without finding the fi

  • Officejet 7612 E All in one printer will not wake up from sleep mode or powersave

    We cannot get a Officejet 7612 to wake up from sleep mode or powersave.  I have tried logging into the web interface but I am only able to delay sleep mode up to 15 minutes.  I need to shut this off or have the issue fixed.  The only way to use the d