MATLAB: Does an “assertion failed” error occur when I use MEMMAPFILE on a large number of input files on MATLAB 7.0.4 (R14SP2)

assertionsmappingMATLABmemmapmemmapfilememory

I am trying to memory map variables specified by a batch of 100 text files using the following code:
fname = 'myfile.txt';
f_cell = {'uint8' , [1 10] , 'myData1' ;
'uint8' , [1 10] , 'myData2' ;
'uint8' , [1 10] , 'myData2' ;
};
for i = 1:100
m = memmapfile(fname , 'format', f_cell , 'offset' , 9);
s = m.data;
end
After many iterations through the loop, I receive the following error:
------------------------------------------------------------------------
Assertion detected at Mon Jul 11 17:20:07 2005
------------------------------------------------------------------------
Assertion failed: BlockNum!=USHRT_MAX, at line 426 of file ".\memmgr\mem32aligned.cpp".
Configuration:
MATLAB Version: 7.0.4.365 (R14) Service Pack 2
Operating System: Microsoft Windows XP
Window System: Version 5.1 (Build 2600: Service Pack 2)
Processor ID: x86 Family 15 Model 7 Stepping 10, AuthenticAMD
Virtual Machine: Java 1.5.0 with Sun Microsystems Inc. Java HotSpot(TM) Client VM
(mixed mode)
Default Charset: ibm-5348_P100-1997
Stack Trace:
Error in ==> memmapfile.memmapfile>subsref__ at 537
val = hSubsref(obj.dataHandle, s(2:end));
<SNIP>

Best Answer

This bug has been fixed in Release 14 Service Pack 3 (R14SP3). For previous product releases, read below for any possible workarounds:
The memory manager in MATLAB 7.0.4 (R14SP2) has a limitation when using MEMMAPFILE on a large number of input files.
To work around this issue, set the MATLAB_MEM_MGR system environment variable to have the value "cache" (without quotation marks). For example, on Windows XP, you can set this environment variable as follows:
1. Right-click the My Computer icon. (On Windows XP, the My Computer Icon may be located in the Start menu.)
2. Choose Properties from the shortcut menu. (Alternatively, you can double-click the System icon in Control Panel.)
3. In the System Properties dialog box, click the Advanced tab.
4. Click the Environment Variables button.
5. Beneath the System Variables box, click New.
6. Supply the variable name MATLAB_MEM_MGR and the value "cache" (without quotation marks).
7. Click OK in the New System Variable dialog box.
8. Click OK in the Environment Variables dialog box.
9. Click OK in the System Properties dialog box.