Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

redundant array declaration

Suppose you have a start button in a VC++ program, and it has a function attached to itself, which will excute certain routine when the button is pressed. In that routine, I want to declare an array using malloc only when I want to such as when there is a change in the input parameter. The problem is the array declaration repeats using "malloc" every time the button is pressed and the array is cleared when the routine is complete using "clear." How can I keep the array alive even after completing the attached function? I tried to declare a global pointer outside the function, but it won't compile of course. For example, suppose you have a program that prompts the user to enter the number of for loop repeat and only the first time the prog
ram runs or only if the total repeat is different from the previous run, you want to redeclare an array using malloc. How can I achieve such task? Thanks in advance for your advice.
0 Kudos
Message 1 of 2
(2,990 Views)
Since you're using C++, you could make the array a member variable of the dialog class, initialize the array when the dialog is created, then use the array in the click message handler of the button, which should be a member method of the dialog class.

Also, since you're using the Measurement Studio C++ libraries, you can use the CNiScalarVector data types (for example, CNiReal64Vector). That way you don't have to worry about memory management via malloc, you will have several useful methods for working with the array from the vector class, and you'll be using a data type that integrates well with the Measurement Studio C++ hardware, analysis, and user interface libraries.

- Elton
0 Kudos
Message 2 of 2
(2,990 Views)