声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 1323|回复: 4

[综合讨论] matlab中的工作空间默认为多大?

[复制链接]
发表于 2006-8-25 10:42 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?我要加入

x
我是否可以在工作空间中开辟任意大的数组?
回复
分享到:

使用道具 举报

发表于 2006-8-25 16:00 | 显示全部楼层
好像不行,大概是1e7左右。

评分

1

查看全部评分

发表于 2006-8-25 20:41 | 显示全部楼层
这个和你的可用物理内存成正比
发表于 2006-9-2 09:16 | 显示全部楼层
查了一下,下面是解答:
Matlab中能开的最大数组是由什么决定的?

I have had similar problems. Below is an explanation I received from
Ian Boyd
from Mathworks (just giving credit where credit is due) that explains
what's happening. You solution is to run matlab with the -nojvm mode.
"The heap memory system in JAVA consists of data and handle elements.
When you allocate a variable you get a handle and data. As long as
data has an associated handle, the JVM considers it valid and
will not clean it up.

However, when you call the clear function in MATLAB, all handles are
destroyed, and the data associated is now invalid. This means that
the JAVA engine can free up that data (garbage collection), but does
not mean that it will clean it up at that moment.

Calling the PACK command encourages JAVA to run the garbage collector
and de-fragment the memory. But it does not force it to (This is part
of the JAVA design). Even though the memory is 'freed' on the heap,
it is not actually free to the OS, it is only free to the JVM. Here
is one way to think of it:

[MATLAB]
[JAVA]
[OS]
MATLAB runs on JAVA (virtual machine), and Java runs on the OS
(physical machine). So when MATLAB is running in JAVA mode memory
allocations are requested from the JRE, not the OS.

One problem you may be running into is that the default maximum
JAVA heap size is relatively low ( <= 64 MB), so that is all the
memory one session of MATLAB will ever get on your system.

The good news is that you can increase this value. You will need
to create a java.opts file in $MATLAB/bin/$ARCH (or in the current
directory when you start MATLAB) and put the following command:

%%%BEGIN CODE%%%
maxHeapSize = 268435456
%%%END CODE%%%

This will give you 256MB of JVM memory and you can adjust the
parameter as needed.

Note: $MATLAB is the root directory and $ARCH is your system
architecture. This solution works on Windows as well as Solaris,
Linux,Alpha, and SGI. A similar operation is possible on IBM and
HPUX, but with a different syntax.

For the 1.1.8 JVM (Windows, Linux, Solaris, Alpha, SGI) our
defaults are:

minHeapSize = 16000000
maxHeapSize = 64000000

These are the structure field names in that correspond to
-ms and -mx, and the settings above are roughly 16MB and 64MB.
To investigate the Java heap a bit, ask via the following:
>> java.lang.Runtime.getRuntime.totalMemory
>> java.lang.Runtime.getRuntime.freeMemory

When the free memory hits zero, Java will double the heap size
(up to the maximum setting).

If you choose to run without Java, you will remove the overhead
of the middle man, but you will also lose some MATLAB functionality
(mostly graphics and the Editor). You will still have most
of the computational power though.

Without JAVA, memory management will come directly from the OS,
and a CLEAR operation will result in memory being freed back to
the OS.


当然,数组越大计算应该越慢,所以应该通过程序优化来避免这样的问题,从而提高效率。
发表于 2006-9-2 10:31 | 显示全部楼层
工作空间中 我试过自己的 65535 就不行了 我的机子转不动了
您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

QQ|小黑屋|Archiver|手机版|联系我们|声振论坛

GMT+8, 2024-9-25 09:34 , Processed in 0.059383 second(s), 19 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表