06-07-2010 09:46 AM
Consider a large string indicator like this:
I would like to append a string quite often (the appended string is read by the serial port), at the same time maintain the last line visualized.
My code is this for the update (executed often, every time I get a new char at the port):
and then this:
Unfortunately this solution has a flickering UI problem, because the whole transmission lasts like 80 seconds, so I think that for every char I get the entire (old) string is copied into another string variable that has only one char more...
Isn't it possible to append just one char? like the StringBuilder object in .NET, to avoid memory waste (under the hood variables are copied) ?
How to avoid the flickering of the indicator?Is DeferPanelUpdates property enough?
Any good practice?
Thanks
06-07-2010 10:14 AM
You are wasting a lot of resources here. Please try this:
Please note that i used a For-Loop due to show the suggested way: Limit the growth of the string. Otherwise, your system will run out of resources (memory) in a short (or perharps longer) time......
hope this helps,
Norbert
06-07-2010 10:19 AM - edited 06-07-2010 10:20 AM
Slyfer wrote:
Isn't it possible to append just one char?
Of course:
But I'm guessing that's not what you're really asking.
like the StringBuilder object in .NET, to avoid memory waste (under the hood variables are copied) ?
You have a misconception on how StringBuilder actually works. The StringBuilder class will allocate a new buffer if the text appended (whether it's one character or 100 characters) exceeds the current buffer for the instance of the StringBuilder class that you have.
You should be aware that continuously building a string can quickly become a resource hog as more and more memory is allocated. A better approach is to have a pre-allocated set of lines and you basically use the buffer like a FIFO or LIFO (depending on the behavior that you want).
How to avoid the flickering of the indicator?Is DeferPanelUpdates property enough?Any good practice?
The flickering is not occuring due to the appending of the strings. The flickering is occurring due to updating the scroll position all the time. My suggestion is to make the scroll movement a little smarter. I.e., don't move it all the time, but only when you need to.
06-07-2010 11:00 AM
06-07-2010 11:05 AM
Slyfer wrote:I got what you mean about StringBuilder buffer. But in that case it is possible to create the object with big buffer (I think it is also handled automatically the case of buffer full). In labview I can only assign variable?! (if one doesn't use the shift register loop)
Yes.