09-15-2011 07:09 PM
imgCreateBuffer seems to run out of memory even though there is plenty available - I recently installed 24 GB and Windows Task Manager only reports about 3-4 GB in use. I create about a dozen buffers OK but then the next few calls give me an Out of Mmeory error. The buffer size is abou 34 MB . This is done in C adaptor that is called through MATLAB. I'm wondering if this could be a 32/64 issue as the MATLAB executable is 32-bit.
09-16-2011 10:23 AM
Patrick,
Was your code working properly prior to upgrading to 24 GB? If so, how big was your memory prior to upgrading? When you referred to the 32/64 bit issue, I'm assuming that you're running a 64 bit OS?
In terms of your problem, I am only qualified to diagnose the problem in terms of the imgCreateBuffer function. Questions about MATLAB compatibility are better suited for the MATLAB User Community
Also, if you wouldn't mind, could you post the section of your code that utilizes the imgCreateBuffer function and point at what point in the code you run out of memory?
Larry H.
09-16-2011 11:10 AM
If MATLAB's executable is only 32-bit, then what you are seeing would be expected as each 32-bit process can only allocate 2GB (or possibly 3-4GB in some cases). If this space is heavily fragmented then you might not have enough contiguous space for larger buffers even if you are not fully exhausting the entire address space.
I would assume if you could switch to a 64-bit version of MATLAB for this then you could allocate a virtually unlimited number of buffers.
Eric
09-16-2011 01:12 PM
Previously I had 6 GB on my system. Here is the code
errChk("\nstartCapture(): ", imgSessionGetBufferSize(sessionID, &bufSize));
mexPrintf("\nbufSize=%d", bufSize);
errChk("\nstartCapture(): imgCreateBufList",imgCreateBufList(numGrabBuffers, &bufListID));
ImaqBuffers = new void*[numGrabBuffers];for (i = 0; i < numGrabBuffers; i++){
sprintf(errMsg, "\nstartCapture(): imgCreateBuffer buffer number = %d", i);
errChk(errMsg, imgCreateBuffer(sessionID, IMG_HOST_FRAME, 0, &ImaqBuffers[i]));
errChk("\nstartCapture(): imgSetBufferElement2 (address)", imgSetBufferElement2(bufListID, i, IMG_BUFF_ADDRESS, ImaqBuffers[i]));
errChk("\nstartCapture(): imgSetBufferElement2 (size) ", imgSetBufferElement2(bufListID, i, IMG_BUFF_SIZE, bufSize));
bufCmd = (i == (numGrabBuffers - 1)) ? IMG_CMD_LOOP : IMG_CMD_NEXT;
errChk("\nstartCapture(): imgSetBufferElement2 (command)", imgSetBufferElement2(bufListID, i, IMG_BUFF_COMMAND, bufCmd));}
errChk is a little utility function that will only print the message when the the img functions return an error code. Here is the output:
bufSize=35715000
startCapture(): imgCreateBuffer buffer number = 59 Not enough memory to perform the operation.
startCapture(): imgCreateBuffer buffer number = 60 Not enough memory to perform the operation.
...
and so on for all 170 buffers I am trying to allocate 🙂
By my calculations, the buffer size is ~34MB and 60 or so buffers would require about 1.6 GB. It probably is a fundamental limitaiton of 32-bit addressing.
01-30-2012 07:55 PM - edited 01-30-2012 07:55 PM
Ok just a little update, with another question ... we have switched over to 64-bit MATLAB. I recompiled my adaptor and got it to run after a changing all the linked libraries to the 64-bit. The problem is after a while, during an acquisition it will crash.
The adaptor code iis the same for the 32-bit version, which doesn't have this crash issue.
Unfortunately debugging this is difficult, I can't even tell where the code is failing (Matlab usually quits without error). It could be on the Matlab Adaptor engine and not my code or NI code at all. I'm using Visual C++ Express Edition 2010 which doesn't have remote debugging and can't compile MFC, which the examples all use. I recall some older examples with the C APi just used Win32 ... something like 'LLGrab.c', etc. but can't find the code for these.
Thanks.
01-30-2012 10:33 PM - edited 01-30-2012 10:42 PM
Hi Patrick,
Without knowing more about what your code is doing or looks like its hard to tell what might be crashing. If you could provide some snippet that exhibits the problem in a simple executable it would help a lot.
As for getting the examples working, are you sure you're not looking at the IMAQdx examples? As far as I know, the IMAQ examples are still written with plain old Win32 APIs (I wish they were updated to use MFC!). Are you looking in C:\Users\Public\Documents\National Instruments\NI-IMAQ\Examples\MSVC\Grab\LL Grab ? Those examples should compile out-of-the-box for 64-bit as well.
One last thing - doesn't MATLAB already have software support for NI IMAQ boards (http://www.mathworks.com/products/imaq/supportedio15271.html)? Is there some reason you're writing your own adapter?
Eric
01-31-2012 12:57 PM
As for getting the examples working, are you sure you're not looking at the IMAQdx examples? As far as I know, the IMAQ examples are still written with plain old Win32 APIs (I wish they were updated to use MFC!). Are you looking in C:\Users\Public\Documents\National Instruments\NI-IMAQ\Examples\MSVC\Grab\LL Grab ? Those examples should compile out-of-the-box for 64-bit as well.
Yes, I found them and will try to get them compiled thanks.
One last thing - doesn't MATLAB already have software support for NI IMAQ boards (http://www.mathworks.com/products/imaq/supportedio15271.html)? Is there some reason you're writing your own adapter?
You cannot chage the camera properties with the Matlab adaptor (i.e., integration time, gain, etc.), or the ROI position, last time I checked. Also, the hardware triggering didn't see to actually work which was a game breaker.