LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

unpredictable buffer allocation and Show Buffer Allocation

Hi,

I try to process large arrays. In order to practice an effective programming style(speed+memory),I would like to avoid producing copies in the memory. However after some experiments I found out that LV8(German edition) sometimes makes useless copies. (That's at least how it seems to me.) To clarify my point I attached 4 simple VI's which need from 1 to 4 buffers for apparently the same logical task. Why are these copies made? Is it a bug? How can I avoid these copies?
(I made my examples only with "Replace Array Subset" but a similar strange behavior can be observed with other "in place" functions e.g. Swap Bytes)

Moreover controling the buffer allocation with the profiling tool "Show Buffer Allocation" does not always show all the buffers used. Why?

I also noticed that after a program modification the refresh button of Show Buffer Allocation does not refresh (recompile) buffer allocation (although the help tells so) but I have to run the program once. (After the run the refresh button only makes the buffers blink). As the program can only be run after everything is complete, the good or bad buffer allocation can only be viewed at the end of the programming process.

Thanks for your answers.
Dalton

Using LabView 2009 on Win XP
Download All
0 Kudos
Message 1 of 13
(5,063 Views)
Hi Dalton:

The Replace Array Subset function, as long as I know,  creates a new array in which the modifications are made, so after the execution of the function, you have two arrays, one containing the original array and other containing the modified array. So that's why you see an unefficient use of memory. I could't check your VI's since I have LabVIEW 7, so I wonder if you can save it for version 7.

Regards.

Robst



Robst - CLD

Using LabVIEW since version 7.0


0 Kudos
Message 2 of 13
(5,039 Views)

Hi All,

The Replace array subset will re-use a buffer if that buffer is appropriate for re-use.

The VI's you poseted along with some others are shown in this image.

I added red arrows to emphesize where the buffer allocations are taking place.

The two examples you provided (4buffer adn 2abuffer) along with my 2cbuffer shows that the bufferproduced by an "Initialze array" that has constant inputs is not suitable for re-use. I can only guess at why an array of predicatable size can can not be re-used Smiley Surprised

On the other hand, buffers produced by an Intialize array of unknown size (at compile time) can be re-used as shown in 1buffer and 2bBuffer.

I added Buffer and Bufferb to show how an input array can be re-used or not re-used. In both of these cases, Array out is the same buffer as Array in. In Bufferb Array out 2 is processed before Array out in order to allow the buffer re-use.

So most of this makes sense to me except all of the buffers in "4Buffer".

Why is an array of constant size un-suitable for re-use?

Why is the array produced by the Replace array subset not re-usable for Array out?

Since replacing the constant derived Initialize array "fixes" the buffer allocations issues I will venture a guess that there is some "constant folding" (Compiler attempts to pre-process constants) or, ..... hmmm

Not sure Smiley Wink

This link talks about how to do the above in LV 7.0

http://digital.ni.com/public.nsf/websearch/C18189E84E2E415286256D330072364A?OpenDocument

This link talks about when buffers are re-used.

http://zone.ni.com/devzone/devzoneweb.nsf/opendoc?openagent&2B85FEE11F13194C86256A370054C805&cat=838...

Anyone else able to shed some light on why the buffers are being over-allocated?

Ben

 

 

Message Edited by Ben on 01-29-2006 12:12 PM

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


@Ben wrote:

The two examples you provided (4buffer adn 2abuffer) along with my 2cbuffer shows that the bufferproduced by an "Initialze array" that has constant inputs is not suitable for re-use. I can only guess at why an array of predicatable size can can not be re-used Smiley Surprised

On the other hand, buffers produced by an Intialize array of unknown size (at compile time) can be re-used as shown in 1buffer and 2bBuffer.

I added Buffer and Bufferb to show how an input array can be re-used or not re-used. In both of these cases, Array out is the same buffer as Array in. In Bufferb Array out 2 is processed before Array out in order to allow the buffer re-use.

So most of this makes sense to me except all of the buffers in "4Buffer".

Why is an array of constant size un-suitable for re-use?

Why is the array produced by the Replace array subset not re-usable for Array out?

Since replacing the constant derived Initialize array "fixes" the buffer allocations issues I will venture a guess that there is some "constant folding" (Compiler attempts to pre-process constants) or, ..... hmmm

Not sure Smiley Wink

This link talks about how to do the above in LV 7.0

http://digital.ni.com/public.nsf/websearch/C18189E84E2E415286256D330072364A?OpenDocument

This link talks about when buffers are re-used.

http://zone.ni.com/devzone/devzoneweb.nsf/opendoc?openagent&2B85FEE11F13194C86256A370054C805&cat=838...

Anyone else able to shed some light on why the buffers are being over-allocated?


The reason a constant array can't be reused is something Greg Mc Kaskle once called indeed constant folding. In principle what LabVIEW does for an Initialize Array functions with constants as inputs is calculating the array at compile time and storing it together with the VI to the disk. This is then a constant array and created at load time rather than runtime and as long as you are not passing it to functions that modify the array, no copy needs to be done. But for modifying functions it can't reuse the array since it is a constant array (and potentially on certain platforms could have been loaded into a read only page) where any attempt to modify the array would create a General Protection Fault error.

Rolf Kalbermatter

Message Edited by rolfk on 01-29-2006 09:41 PM

Message Edited by rolfk on 01-29-2006 09:46 PM

Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
Message 4 of 13
(5,018 Views)
Hi All,

And thank's for your answers.

Ben suggested that CONSTANT Arrays (Or Build Array with constants) will produce NOT REUSABLE BUFFERS. (Thank's for the pictures Ben. Do you use any special screen capture or picture manipulating or exporting programs?) RolfK confirmed this and pointed out that this has been mentioned before by Greg Mc Kaskle under the term of "constant folding". (Is there any link to this issue. I understood the sense but I am not familiar with the term).

In fact I always try to reuse buffers and have read some counseling articles about reusing buffers in the help, manuals and white papers but didn't find this point.

After further experimenting I have to add that not only the first constant array is not reusable but the "virus of copying" spreads through all following functions even if these, in principle, could reuse the buffer. This is an important point: CONSTANT arrays can SPOIL YOUR PROGRAM.

To me the reuse of buffer is a point of major importance in LV-programming! (As I try to optimize memory use and first of all SPEED. As experimented LV-programmers know data copies (in loops) can terribly slow down your program.) Is there an exhaustive compendium of the DO's and DONT'S of buffer reuse and of the compiler decision rules, maybe with the assistance of National Instruments?
(I repeat Ben's important piece of information
http://zone.ni.com/devzone/devzoneweb.nsf/opendoc?openagent&2B85FEE11F13194C86256A370054C805&cat=8382DFCE5A73BBDD862567AC005842AB )
I need more of this stuff. For example lists of functions which reuse buffer or don't. And Why! It's not so clear to me why some data manipulating functions do not reuse buffer even if they could be memory conservative. e.g. type cast array U32 to U8)

In addition to the above I would like to stress that in the example VI's of my first message LV does indeed use even more buffers than shown by the tool Show Buffer Allocation! This can be seen by increasing the array size to 10 MegaBytes or so and using the Windows Task Manager to monitor the memory really used! 2bBuffer uses 2 Buffers but only 1 is shown and 4Buffer uses 4 Buffers but only 3 are shown! This puzzles me because with that I even cannot rely on "Show Buffer Allocation" to show me all buffers used!

My last point may be a bagatelle but in my LV8 the refresh button does not recompile and redisplay the buffers used but I have to rerun the programm before the refresh button lets the buffers blink.

Dalton
Dalton

Using LabView 2009 on Win XP
0 Kudos
Message 5 of 13
(4,984 Views)

Dalton wrote

"

In addition to the above I would like to stress that in the example VI's of my first message LV does indeed use even more buffers than shown by the tool Show Buffer Allocation! This can be seen by increasing the array size to 10 MegaBytes or so and using the Windows Task Manager to monitor the memory really used! 2bBuffer uses 2 Buffers but only 1 is shown and 4Buffer uses 4 Buffers but only 3 are shown! This puzzles me because with that I even cannot rely on "Show Buffer Allocation" to show me all buffers used!
"

Warning!... just guessing now!

I think the extra buffer may be the duplication that occurs between BD data and FP data.

Re: Screen captures

I just use "print Screen" and paste into paint.

(This reminds me of a website and does not apply to you Dalton.

After filling out a form the web-site directs you to a page that has instructions on how to print out a hard-copy for your records. It reads something like, "If you are using Windows do a "File >>> Print" if you are using MacOS then use "Apple >>> blah, blah blah" if you are using Linix, you do need to be told how to print a screen Smiley Wink ).

The "Constant Folding" bit was just a wild guess based on a old thread that I would be hard pressed to find.

Thank you Rolf!

... for filling in some blanks. After reading your comments this make a lot of sense and re-using the constant array buffer would actually allow data to flow backwards!

Dalton,

I would also like to read more articles discussing how and when buffers are re-used.

If you would like, please send me your best agruement for more articles of this type and I will send it to my inside contact who wants to hear about what user want to read about. My e-mail is

bar@dsautomation.com

PLEASE include a subject that mentions the developer Exchange! I delete 75-100 junk mails a day! Smiley Mad

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 6 of 13
(4,974 Views)

Here is a link to the thread were I first heard of constant folding

http://forums.ni.com/ni/board/message?board.id=BreakPoint&message.id=911&jump=true

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 7 of 13
(4,968 Views)
_____________
Dalton Wrote:

My last point may be a bagatelle but in my LV8 the refresh button does not recompile and redisplay the buffers used but I have to rerun the programm before the refresh button lets the buffers blink.
_____________

This is still a problem in LV8.20. The Refresh button doesn't recompile apparently! I am forced to do a Ctrl+Shift+Click_on_Run every time to get this to refresh... @#$%!!

Have reported this to NI.

-Khalid
Message 8 of 13
(4,823 Views)

Thanks for the above discussion and links. I was unaware of the above and was doing some tests on my own and found out that using constants to initialize an array were eating up more memory than my calculations. This led me to investigate further into buffer allocations, then finally search the Zone on the same.

-AK2DM

~~~~~~~~~~~~~~~~~~~~~~~~~~
"It’s the questions that drive us.”
~~~~~~~~~~~~~~~~~~~~~~~~~~
0 Kudos
Message 9 of 13
(4,743 Views)

Khalid,

I also encountered this problem and found that I could get the refresh button on the buffer allocation screen to work only after I save my file.  I guess this also recompiles the code.

 

Regards,

mlloyd

0 Kudos
Message 10 of 13
(4,634 Views)