如何直接在Matlab中增加Java堆大小? [英] How to Increase Java Heap Size directly in Matlab?

查看:789
本文介绍了如何直接在Matlab中增加Java堆大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过Matlab命令直接增加Java堆的大小,因为我需要根据环境进行动态控制. 我知道线程

I would like to increase the Java heap size directly by Matlab command because I need dynamic control depending on the environment. I know the thread How do I increase the heap space for the Java VM in MATLAB 6.0 (R12) and later versions where they say to use java.opts file but I would like to do the same with Matlab prompt directly. There are many threads that offer to change the parameters only through Matlab GUI or the file, like Matlab's blog post Controlling the Java Heap Size.

我有兴趣动态地增加这些参数

I am interested in increasing these parameters dynamically

heapSizeMemoryDefault = 521142272; % 512 MB
assert(java.lang.Runtime.getRuntime.maxMemory > heapSizeMemoryDefault*2, 'Java heap size too small');
runTimeMemoryDefault = 90116624; % about 890 MB
assert(java.lang.Runtime.getRuntime.freeMemory > 90116624*2, 'Java free memory size too small');


如何在Matlab 2016a中直接增加Java堆大小?


How can you increase Java heap size directly in Matlab 2016a?

推荐答案

有几种方法可以通过编程方式更改Java堆大小,但是所有方法都需要重新启动Matlab,因为堆大小是在启动时分配的.

There are a few ways to change java heap size programmatically, but all require Matlab restart, since heap size is allocated at startup.

要从首选项文件中查询最大堆大小设置:

To query max heap size setting from preferences file:

oldMaxHeapSize = com.mathworks.services.Prefs.getIntegerPref('JavaMemHeapMax');  % MB

零结果表示首选项文件中没有设置,这导致分配了一些默认大小.

Zero result means there is no setting in the preference file yet, which results in some default size allocated.

要在首选项文件中设置最大堆大小 setting :

To set max heap size setting in preferences file:

com.mathworks.services.Prefs.setIntegerPref('JavaMemHeapMax', 2048); % MB

记住要重新启动Matlab,例如使用quit()结束当前过程.经过测试并在Matlab> = R2013b上工作.

Remember to restart Matlab, e.g. use quit() to end current process. Tested and works on Matlab >= R2013b.

请注意,这些命令基本上只是编辑matlab.prf文件的一种编程方式,位于Windows安装程序中(使用正确的Matlab版本)C:\Users\%USERNAME%\AppData\Roaming\MathWorks\MATLAB\R2013b\matlab.prf

Note that these commands are basically just a programmatic way to edit the matlab.prf file, located in Windows installations at (use correct Matlab version) C:\Users\%USERNAME%\AppData\Roaming\MathWorks\MATLAB\R2013b\matlab.prf

例如在这种情况下,我们正在编辑以下设置(您可以在执行命令以检查是否设置了新值之后打开文件)

E.g. in this case, we're editing the following setting (you may open the file after you execute the command to check new value is set)

JavaMemHeapMax=I2048

文件中还有许多其他有用的设置,可以用类似的方式查询/设置.

There are plenty of other useful settings in the file which can be queried / set in a similar fashion.

这篇关于如何直接在Matlab中增加Java堆大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆