Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

Visual Studio 2008 C++ Out of Memory exception

Is anyone available that could run an eye over some Visual Studio 2008 C++
.NET3.5 code and render an opinion as to what may be causing an Out Of Memory
exception to be thrown?  The forums I've found so far seem to be C# or 
Labview or Measurement Studio centric.  The example is simple: in a tight loop

 gcnew a Task, gcnew a Digital Channel, open a reader for a single line, read the

value, close the reader, repeat.  Supposedly, the GC will clean up the

gcnew’ed stuff but, eventually, throws the OOM at my code, anyway.  The only thing

I find in the MSDN is to use GC.Collect, from some very old (ca 2007, pre 2008)

answers.  This solution doesn't seem to work, and I'm thinking that I might have to

do the gcnew's in the constructor of the class, rather than at the time of reading the

digital line. Can anyone offer advice? Thanks.

0 Kudos
Message 1 of 6
(4,250 Views)

Hi pnorisez,

 

NationalInstruments.DAQmx.Task interfaces with unmanaged code, which allocates resources that the GC can't track, so it implements IDisposable. Destructors and Finalizers in Visual C++ talks about about how IDisposable maps to C++. Try deleting the task instead of leaving it up to the GC.

 

Brad

 

---
Brad Keryan
NI R&D
0 Kudos
Message 2 of 6
(4,243 Views)

Brad's suggestion seems to have helped partially.  Now I get a memory write exception.  It appears that some pointer or handle is getting corrupted in the Windows forms, causing a textbox to have garbage in it, just before the memory write exception occurs.  Is this related to some of the other issues I've seen on here where file corruption occurs due to using the unmanaged DAQ driver from managed code?  Could the same patch fix it?  I don't know.  Any help will be appreciated.

0 Kudos
Message 3 of 6
(4,224 Views)

More info:  The DAQmx version I am using is NI-DAQmxtm 9.5.0.  I am using it in a 32-bit application running on Win7 64-bit.  The card is a 6353 for pci express.

0 Kudos
Message 4 of 6
(4,219 Views)

> Is this related to some of the other issues I've seen on here where file corruption occurs due to using the unmanaged DAQ driver from managed code?

 

Are you asking about this issue? Visual Studio Projects Referencing National Instruments Drivers May Cause Blue-Screens and File Corr...

 

I don't know what version of NI-DAQmx you're using [Edit: You posted it while I was writing this reply. 9.5.0 should be fine.], but that issue was fixed in NI-PAL 2.6.5. NI-DAQmx 9.3 and later includes the fixed version of NI-PAL.

 

Also, that issue tended to crash the entire system. Is your memory write exception a system crash or an application crash? What was the exact error message? If it's an application crash, I recommend using the Visual Studio debugger to determine the cause.

 

Brad

---
Brad Keryan
NI R&D
0 Kudos
Message 5 of 6
(4,218 Views)

Are you asking about this issue? Visual Studio Projects Referencing National Instruments Drivers May Cause Blue-Screens and File Corr...

 

Yes, but you seem to have covered it in later sentences.

 

Is your memory write exception a system crash or an application crash?

 

It is an application "crash".  Actually the programmer with which I am working catches the exception after it occurs.  He is working his way down from this complex app to see what can be discovered.  Debugging does not shed any light, as the corruption occurs long before it can be trapped.  One note, the exception only occurs after a couple of trips through the same code.

 

What was the exact error message?

 

"Attempted to read or write protected memory.  This is often an indication that other memory is corrupt."

 

Also, I have coded a much smaller WIndows/forms app that doesn't seem to have the issue.  This app uses the same DLL that I am developing, so should be in the same jeopardy.  I am continuing to work my way up from this simple app to more comlexity to see if there is a critical point.

0 Kudos
Message 6 of 6
(4,212 Views)