ni.com is currently undergoing scheduled maintenance.

Some services may be unavailable at this time. Please contact us for help or try again later.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

unwanted storage in shift register?

Greetings all;
Can any one tell me if an initialized shift register remembers its
contents between calls to the vi? I use a shift register to hold an
array of complex clusters, and if this information is not eliminated
between calls, this would represent a very large waste of physical
memory. If this is the case, is there any way to force LV to clear the
memspace of this one vi ASAP ?

Cheers!
0 Kudos
Message 1 of 4
(4,622 Views)
> Can any one tell me if an initialized shift register remembers its
> contents between calls to the vi? I use a shift register to hold an
> array of complex clusters, and if this information is not eliminated
> between calls, this would represent a very large waste of physical
> memory. If this is the case, is there any way to force LV to clear the
> memspace of this one vi ASAP ?
>

Initialized Shift registers do not have side effects between calls,
in other words, the previous data isn't used in the next call. That
doesn't mean that the data is released though. The buffer for the
array is kept around assuming that the next call will have a similar
sized array that needs to be stored. In essence it trades memory for
speed and optimizes for the execution speed.


You could turn on the Deallocate Memory preference on the performance
page, but I wouldn't advise it. This setting is global and the frequent
resizing can actually make the system memory manager fragment worse and
use more memory than before due to the fact that most system memory
managers never compact. Instead, I'd recommend that you selectively empty
the shift registers yourself. You can write anything you want to the shift
register on right hand side on the last iteration. This means that the last
iteration of your loop, set the value to an empty array or whatever you like.
If you need the value previously stored in the shift register, then you
should send the value out of the loop in a tunnel rather than the shift
register.

Greg McKaskle
Message 2 of 4
(4,621 Views)
That's something I bet I've overlooked before!


>If you need the value previously stored in the shift register, then you
>should send the value out of the loop in a tunnel rather than the shift
>register.
>
>Greg McKaskle
0 Kudos
Message 3 of 4
(4,621 Views)
In <3780FDE6.CBBFCA63@courrier.usherb.ca> Paul Rowntree writes:
>Can any one tell me if an initialized shift register remembers its
>contents between calls to the vi?

The purpose of initializing a shift register is to define contents and
buffer size that will remain each time the associated loop iterates.
If you place the initialized outside the main loop of the entire
program, that initialization (and storage) will remain throughout the
duration of the program. If you place the initialization inside the
program, that shift register will get re-initalized each time it starts
the first iteration of that internal loop.

>I use a shift register to hold an
>array of complex clusters, and if this information is not eliminated
>between calls, this would represent a very large waste of physical
>memory. If this is the case, is there any way to force LV to clear the
>memspace of this one vi ASAP ?

You can assign it to an empty array upon exiting the loop. Storage
may not be release immediately after this assignment, but after
exiting the subvi containing this loop, the memory manager should try
to garbage collect this released space if a new array allocation in
another subvi needs it.

SOME THOUGHTS:

A better question to ask might be, "Do I want to free up this unused
space in the first place?" Typically, the answer is "no" because this
unused space can be reserved and allocated to the next array that
needs to make use of this shift register. In other words, by not
freeing the space, we are saving the memory manager from extra work
garbage collecting released array space that will only need to be
allocated again and again.

Now if you have a *really*big* array that's using every last speck of
memory in your system, then it might be worthwhile to release it as
soon as possible. Just be sensitive to the fact that you may be
creating more pointless work for the memory manager as far as garbage
collection is concerned.
--
/\ Mark M Mehl, alias Superticker (Supertickler to some)
<><> Internet: mehl@IAstate.edu
\/ Preferred UUCP: uunet!iastate.edu!mehl
Disclaimer: You got to be kidding; who would want to claim anything I said?
0 Kudos
Message 4 of 4
(4,621 Views)