01-09-2017 02:03 AM
Greetings! I am a freshmen for LabWindows/LabVIEW. Thank you for any response in advance.
Recently, I need to develop a VI using C code, so I am trying to use LabWindows to develop a .DLL file. My function looks like:
int32_t myFunc(double output[], int32_t input_len, double input[], int32_t interleaver[])
{
.....
if ((output=(double *)malloc(length_total*sizeof(double)))==NULL)
{
printf("\n fail to allocate memory of tempout \n");
exit(1);
}
.........
}
as you can see, a vector called 'output' is required for return. For convenience, I allocate space by using 'malloc' here without 'free' it, of course.
The 'output' port is then connected to the next VI.
My question is whether this function will lead to memory leak if I schedule this VI in a loop structure?
01-10-2017 09:25 AM
Hi Jaden,
Are you passing the output array as reference? Right now the function only returns an int.
To answer your question, if you do call this function in your VI in a loop, it will lead to a memory leak.
I hope this helps!
01-17-2017 07:03 PM - edited 01-17-2017 07:04 PM
Hi thuyanhl,
Thank you so much for the response. I found the original code didn't return the ouput[] as a 1D-array by using this method. Thus I finally initialized output[] in the VI and passed it to the C code, then malloc was not required any longer.
Thank you again for your help.