What is the stack size of MATLAB?

穿精又带淫゛_ 提交于 2019-12-07 08:04:19

问题


What is the default stack size of MATLAB R2018a (64-bit)?

It seems that the stack-size is larger than an 64-bit C# program.

Why I'm asking that

I'm asking this question because I'm calling Intel MKLs LAPACKE_dtrtri which is heavily recursive.

I'm using that function inside .NET application and I'm getting a stack overflow error when calling it from C#, see What is the stack size of a BackgroundWorker DoWork Thread? Is there way to change it?

On the other side if I call my .NET application from MATLAB I'm not getting a stack overflow error. That's the reason I wanted to know what the stack size of MATLAB.


回答1:


Using the GetCurrentThreadStackLimits function from kernel32.dll I can get the stack size of MATLAB.

I've created the following helper method in an .NET assembly called IntelMKL.dll:

static class _kernel
{
    [DllImport("kernel32.dll")]
    internal static extern void GetCurrentThreadStackLimits(out uint lowLimit, out uint highLimit);
}

and

public static class MKL
{
    public static uint GetStackSize()
    {
        uint low, high;
        _kernel.GetCurrentThreadStackLimits(out low, out high);
        return high - low;
    }
}

I can call the GetStackSize from MATLAB using the following code:

NET.addAssembly('IntelMKL.dll')
IntelMKL.MKL.GetStackSize() % this return 67108864 Bytes which is 64 Mega Bytes

The stack size of MATLAB is 64 MB.

It seems that the stack-size is larger than an 64-bit C# program.

The default C# stack size is 1 MB (32-bit) and 4 MB (64-bit), see What is the stack size of a BackgroundWorker DoWork Thread? Is there way to change it?




回答2:


Using the dumpbin command I can take look at the header of the MATLAB.exe.

dumpbin /headers "C:\Program Files\MATLAB\R2018a\bin\win64\MATLAB.exe"

This returns

Dump of file C:\Program Files\MATLAB\R2018a\bin\win64\MATLAB.exe

PE signature found

File Type: EXECUTABLE IMAGE

FILE HEADER VALUES
            8664 machine (x64)
...

OPTIONAL HEADER VALUES
...
         4000000 size of stack reserve
            1000 size of stack commit
          100000 size of heap reserve
            1000 size of heap commit

The size of stack reserve is the stack size in hex.

So the stack size of MATLAB is 67108864 Bytes which is 64 Mega Bytes.




回答3:


While I do not have a direct answer to your question, MATLAB's recursion limit can be obtained by get(0,'RecursionLimit') or set by set(0,'RecursionLimit',N).

I believe than other than that, MATLAB will keep storing variables until your RAM runs out, but not 100% sure.



来源:https://stackoverflow.com/questions/56457801/what-is-the-stack-size-of-matlab

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!