matlab程序碰到out of memory的问题真是让人崩溃的一件事情,程序是别人的,不能做大的改动,只能想办法增加内存。别人总结的可用的方法有:
1. 增加虚拟内存:右击我的电脑—属性--高级--性能设置--高级--虚拟内存更改,按自己电脑的硬盘在自定义大小里设置数字,然后再按设置-确定,然后重启。否则更改无效。
对XP,我发现即使增大虚拟内存到4G, matlab可用虚拟内存仍只有2G。仍然out of memory.
>> feature('memstats')
Physical Memory (RAM):
In Use: 611 MB (26364000)
Free: 1428 MB (59418000)
Total: 2039 MB (7f77c000)
Page File (Swap space):
In Use: 470 MB (1d628000)
Free: 4481 MB (118156000)
Total: 4951 MB (13577e000)
Virtual Memory (Address Space):
In Use: 400 MB (190d3000)
Free: 1647 MB (66f0d000)
Total: 2047 MB (7ffe0000)
Largest Contiguous Free Blocks:
1. [at 20017000] 675 MB (2a3f9000)
2. [at 4b033000] 253 MB ( fd8d000)
3. [at 18010000] 127 MB ( 7ff0000)
4. [at 68ff7000] 64 MB ( 4009000)
5. [at 6d7c5000] 56 MB ( 389b000)
6. [at 62c29000] 50 MB ( 3207000)
7. [at d330000] 44 MB ( 2ca0000)
8. [at 663dd000] 41 MB ( 2983000)
9. [at 60809000] 36 MB ( 2417000)
10. [at 5adf7000] 35 MB ( 2379000)
======= ==========
1385 MB (569d4000)
对Vista系统,可能是因为我在第四步设置了命令3GB switche:可用最大虚拟内存是3G
>> feature('memstats')
Physical Memory (RAM):
In Use: 1082 MB (43a3a000)
Free: 1467 MB (5bb96000)
Total: 2549 MB (9f5d0000)
Page File (Swap space):
In Use: 1227 MB (4cbe3000)
Free: 5315 MB (14c36e000)
Total: 6543 MB (198f51000)
Virtual Memory (Address Space):
In Use: 501 MB (1f5bf000)
Free: 2570 MB (a0a21000)
Total: 3071 MB (bffe0000)
Largest Contiguous Free Blocks:
1. [at 1b010000] 1074 MB (432d0000)
2. [at 7fff0000] 1023 MB (3ff9c000)
3. [at 5e302000] 227 MB ( e32e000)
4. [at 7c41b000] 50 MB ( 32d5000)
5. [at 6d857000] 30 MB ( 1e09000)
6. [at 6f66b000] 21 MB ( 1595000)
7. [at 715c3000] 20 MB ( 149d000)
8. [at 7a038000] 18 MB ( 12f8000)
9. [at 739a6000] 17 MB ( 114a000)
10. [at 70c41000] 9 MB ( 94f000)
======= ==========
2494 MB (9be3b000)
2. 采用PACK: 试了不管用
3. 条件允许的话采用64位系统:32位免谈
4. 采用3GB switch: 由于32位 Windows 操作系统的限制,每个进程只能使用最多 2GB 的虚拟内存地址空间,因此 Matlab 的可分配内存也受到相应的限制。Matlab 7.0.1 引进了新的内存管理机制,可以利用 Windows 的 3GB 开关,使用 3GB 开关启动的 Windows 每个进程可以在多分配 1 GB 的虚拟地址空间。我的笔记本是vista系统,台式机是XP系统。
1)对vista系统:Bcdedit 位于X:\Windows\system32\ "X:"为安装Vista的盘符,利用Bcdedit命令,可以自定义你的Vista启动管理项。使用命令: BCDEdit /set increaseuserva 3072 ,DOS界面显示操作成功,注意虚拟内存应设成大于3G,否则内存分配<3G。可在matlab里使用 system_dependent memstats或feature('memstats')命令查询。
2)对XP:右键单击我的电脑--->>属性--->>高级--->>启动和故障修复--->>设置--->>编辑--->>将最后一行multi(0)disk(0)rdisk(0)partition(1)\WINDOWS="Microsoft Windows XP Professional" 复制,在下一行粘贴,并将粘贴一行改为: multi(0)disk(0)rdisk(0)partition(1)\WINDOWS="Microsoft Windows XP Professional with 3GB switche" /3gb --->>存储--->>确定--->>重新启动计算机--->>在显示选择操作系统时,选择带有 3GB switche的一项--->>打开matlab。可是我设置完重启计算机,选择3GB switche的一项时,显示lsass.exe 应用程序错误,无法登陆!看来我的XP系统不支持3GB switche模式登录,因此matlab的可用虚拟内存不会超过2G。
5. 优化程序,减少变量
6. 如果必有必要,不要启动java虚拟机,采用matlab -nojvm启动
7. 关闭Matlab Server