Matlab-在程序中间调用mex文件时内存不足

Matlab-在程序中间调用mex文件时内存不足,matlab,memory,Matlab,Memory,我问这个问题是因为我自己没能解决它,希望有人能给我任何建议 我的问题是: 我的计划包括3个部分: part-1: video encoder, part-2: channel coding - also call to a mex-files: complie from C-function "encodeBits.c" to Matlab-mexfile "encodeBits.mexw32", part-3: video decoder. 我还执行4项检查: 检查1:第1部分+第2部分

我问这个问题是因为我自己没能解决它,希望有人能给我任何建议

我的问题是:

我的计划包括3个部分:

part-1: video encoder, 
part-2: channel coding - also call to a mex-files: complie from C-function "encodeBits.c" to Matlab-mexfile "encodeBits.mexw32", 
part-3: video decoder.
我还执行4项检查:

检查1:第1部分+第2部分作为一个整体。这意味着没有信道编码,程序运行良好

检查2:第2部分的伪输入,表示第2部分保持独立。第二部分运作良好

part-2 still works well even under this condition:
                possible array:             **632** MB (6.623e+08 bytes) *
                Memory available for all arrays:   **1054** MB (1.105e+09 bytes) **
                Memory used by MATLAB:              653 MB (6.842e+08 bytes)
                Physical Memory (RAM):             2795 MB (2.930e+09 bytes)
检查3:第1部分+第2部分+第3部分作为一个整体

    memory before part 1 runs:
        Maximum possible array:             877 MB (9.199e+08 bytes) *
        Memory available for all arrays:   1265 MB (1.326e+09 bytes) **
        Memory used by MATLAB:              441 MB (4.628e+08 bytes)
        Physical Memory (RAM):             2795 MB (2.930e+09 bytes)
    memory before part-2 runs, means after part-1 finished:
        Maximum possible array:             **869** MB (9.107e+08 bytes) *
        Memory available for all arrays:   **1270** MB (1.332e+09 bytes) **
        Memory used by MATLAB:              430 MB (4.511e+08 bytes)
        Physical Memory (RAM):             2795 MB (2.930e+09 bytes)
    and it results error right after part-2 starting with error
        Error using encodeBits
        Out of memory. Type HELP MEMORY for your options.
检查4:在清除检查3中的所有变量后,再次尝试单独使用第2部分 它仍然会导致错误

        Error using encodeBits
        Out of memory. Type HELP MEMORY for your options.
检查5:关闭Matlab窗口,打开Matlab窗口并单独运行第2部分
它工作得很好

part-2 still works well even under this condition:
                possible array:             **632** MB (6.623e+08 bytes) *
                Memory available for all arrays:   **1054** MB (1.105e+09 bytes) **
                Memory used by MATLAB:              653 MB (6.842e+08 bytes)
                Physical Memory (RAM):             2795 MB (2.930e+09 bytes)

因此,我无法理解为什么会发生这种情况,我试图努力搜索,但仍然无法解决它。

根据您在mex调用时/之后的负载下检查失败,以及使用“全部清除”不修复它来判断,听起来您的mex代码中有内存泄漏。如果MEX函数分配内存而未清除内存,则matlab无法清除空间,因此在关闭matlab之前,它将保持分配状态。

您知道触发
内存不足错误的代码行吗?
您能简化产生错误的代码吗?谢谢您的评论,触发错误的代码是:简化代码:第1部分:将图像读取到数组中并生成名为“source”的位流第2部分:将“source”编码为非常小的位流名称“acumsyndrome”acumsyndrome=encodeBits(source,ladderFile);其中:encodeBits是从C encodeBits.C函数编译而来的函数。功能:执行名为LDPCA输入1的信道编码。比特流(0/1),2。作为奇偶校验矩阵输出的数组:奇偶校验位的比特流。谢谢你的帮助另一方面,我不明白为什么第二部分可以在低资源条件下完美地工作,如检查2,而第二部分不能在高资源条件下工作如检查3。非常感谢。