Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

Why do I get error code -50352 , memory could not be allocated

Using PCI 6229 with DAQmx (in C language), I am getting the error code -50352 'the requested memory could not be allocated' after 2 days of running.
Why do I get this ? How can I free the memory ?
0 Kudos
Message 1 of 6
(4,949 Views)


@Dricus wrote:
Using PCI 6229 with DAQmx (in C language), I am getting the error code -50352 'the requested memory could not be allocated' after 2 days of running.
Why do I get this ? How can I free the memory ?




Are you looping, and creating a task each time through the loop? That is, are you calling DAQmxCreateTask() inside the loop? If so, you should be calling DAQmxClearTask at the bottom of the loop every iteration.

Are you allocating an array to receive data read during a loop? If you allocate it inside the loop, you must de-allocate it inside the loop as well.

Hope this helps.
John Weeks

WaveMetrics, Inc.
Phone (503) 620-3001
Fax (503) 620-6754
www.wavemetrics.com
0 Kudos
Message 2 of 6
(4,940 Views)
Hi John,

Indeed, I am looping and creating a new task each time. The rate is about 1 new task per second.
I also do a clear task, calling DAQmxStopTask() and following with DAQmxClearTask().
And as you feel, I am allocating an array to sample 1000 values each loop.
-> DAQmxReadAnalogF64(TaskAnalog1, 1000, 10#, DAQmx_Val_GroupByChannel, readArray(0), 1000, sampsPerChanRead1, 0)

Then you meant that this memory error is not due to a bad use of the DAQ card but rather due to a bad management of the computer memory ?
Indeed, I cannot make it clear whether the PCI card memory is involved or not.

Dricus
0 Kudos
Message 3 of 6
(4,913 Views)
If you have something like this:

TaskHandle h;
double *array;
loop // there are lots of ways to write a loop...
{
DAQmxCreateTask(&h);
...
array = malloc(sizeof(double)*1000);
DAQmxReadAnalogF64(... array, ...);

DAQmxStopTask(h);
DAQmxClearTask(h);
}

Every time through the loop an array of 1000 doubles is allocated, but not freed. So every iteration you use another 8000 bytes of memory.

But if you do something like this:

TaskHandle h;
double array[1000];
loop // there are lots of ways to write a loop...
{
DAQmxCreateTask(&h);
...
DAQmxReadAnalogF64(... array, ...);
... Do something with the data ...
DAQmxStopTask(h);
DAQmxClearTask(h);
}

then you are not allocating new memory inside the loop.

In your post, you have DAQmxReadAnalogF64(... readArray(0) ...). I guess you're not using C. Is that Visual Basic? How do you create readArray? My pseudo-code above is based on C.
John Weeks

WaveMetrics, Inc.
Phone (503) 620-3001
Fax (503) 620-6754
www.wavemetrics.com
Message 4 of 6
(4,894 Views)
John,

--------------------------------------------------------------------------------------------------------------------------------------------
In your post, you have DAQmxReadAnalogF64(... readArray(0) ...). I guess you're not using C. Is that Visual Basic? How do you create readArray? My pseudo-code above is based on C.
--------------------------------------------------------------------------------------------------------------------------------------------

Indeed, you do guess right ; my code is in Visual Basic but version 6.0 that means that I should rewrite DAQmx C functions in VB6.0 to be able to use my PCI card (with DADmx rather than DAQ traditional).
Then I was adapting what you said in C.

As you suppose, I do create my array within a function called from a loop. Then I think you found out what causes trouble.
I took the array declaration out the loop, and this should work better. I will see in a few days !

By the way, it is easy to free memory in C but in Visual Basic 6.0 ? I thought VB was dealing with it !


Thank you very much indeed John,

Dricus


Here after was my code (in short):

Public Function AI_LitTensionMoy() As Double
Dim TaskAnalog1 As Long
[...]
Dim readArray(0 To 1000) As Double

' Create the DAQmx task.
DAQmxErrChk DAQmxCreateTask("", TaskAnalog1)

DAQmxErrChk DAQmxCreateAIVoltageChan(TaskAnalog1, "Dev1/ai7", "", 10083, tensionMin1, tensionMax1, 10348, "")

' Start the DAQmx task.
DAQmxErrChk DAQmxStartTask(TaskAnalog1)

DAQmxErrChk DAQmxReadAnalogF64(TaskAnalog1, 1000, 10#, DAQmx_Val_GroupByChannel, readArray(0), 1000, sampsPerChanRead1, 0)

' All done!
DAQmxErrChk DAQmxStopTask(TaskAnalog1)
DAQmxErrChk DAQmxClearTask(TaskAnalog1)


' Then returns the readArray average value

End Function
0 Kudos
Message 5 of 6
(4,883 Views)
I'm afraid I don't know anything about Visual Basic. Hopefully someone else will be able to answer your question.
John Weeks

WaveMetrics, Inc.
Phone (503) 620-3001
Fax (503) 620-6754
www.wavemetrics.com
0 Kudos
Message 6 of 6
(4,868 Views)