Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

DAQmxWriteAnalogF64 clean up dynamically allocated data

Solved!
Go to solution

I want to use a dynamically allocated memory in a call to DAQmxWriteAnalogF64.

 

float64 *data = malloc( dataPoints );

...

...

 

The call works as expected but I am not able to free the memory without an error. Even after the task is stopped and cleared I cannot clean up the allocated memory. 

 

DAQmxStopTaks( taskHandle );

DAQmxClearTask( taskHandle );

if( data )

{

free(data);  // causes error

}

0 Kudos
Message 1 of 3
(2,876 Views)
Solution
Accepted by topic author Chris_c++

Hi Chris_c++,

 

Can you show your code for filling in the data buffer and passing it to DAQmxWriteAnalogF64? If you write past the end of the buffer, the C runtime library's memory allocator may crash or terminate the application with a runtime error when you call free(). My guess is that you really need to allocate dataPoints * sizeof(float64) bytes, not dataPoints bytes.

 

Brad

---
Brad Keryan
NI R&D
0 Kudos
Message 2 of 3
(2,867 Views)

Hi Brad,

 

My mistake. You are correct. 

 

Thank you for the response!

0 Kudos
Message 3 of 3
(2,862 Views)