matlab程序碰到out of memory的问题真是让人崩溃的一件事情,程序是别人的,不能做大的改动,只能想办法增加内存。别人总结的可用的方法有:
1. 增加虚拟内存:右击我的电脑—属性--高级--性能设置--高级--虚拟内存更改,按自己电脑的硬盘在自定义大小里设置数字,然后再按设置-确定,然后重启。否则更改无效。
对XP,我发现即使增大虚拟内存到4G, matlab可用虚拟内存仍只有2G。仍然out of memory.
% R2 ~! d) O q6 h
>> feature('memstats')7 _) O5 j, d7 B8 P6 E$ B7 i
Physical Memory (RAM):# j5 A O( ?+ t
In Use: 611 MB (26364000)
; _: M0 l6 s& QFree: 1428 MB (59418000)
* e" E0 w4 l4 \Total: 2039 MB (7f77c000)
% U% g! {! C c# P1 v( K; fPage File (Swap space):4 q: L! ]: f7 I. Y. m( b0 t
In Use: 470 MB (1d628000)
: v" M9 k6 P+ L& b& ?/ i$ w: T+ nFree: 4481 MB (118156000)
+ P( S3 ?) t, i$ X/ q, x2 JTotal: 4951 MB (13577e000)
+ C! p3 S1 N. L* Z3 ~5 NVirtual Memory (Address Space):
2 ~: r, [+ N/ f4 `In Use: 400 MB (190d3000)
$ ?( W" z$ V5 r5 u- ^$ g2 ^' zFree: 1647 MB (66f0d000)
G& A1 m& s8 j/ X+ Q, i9 pTotal: 2047 MB (7ffe0000)
4 m& L8 D Z4 n7 Y/ w( ALargest Contiguous Free Blocks:
X8 g& j2 P8 V' z1 Y& T7 F) ?1. [at 20017000] 675 MB (2a3f9000)
8 d6 T; e6 H. k* M2. [at 4b033000] 253 MB ( fd8d000)
0 V* P- m8 b1 L. r# \3. [at 18010000] 127 MB ( 7ff0000)8 V- n* N. p7 [$ ~# ~6 z+ p
4. [at 68ff7000] 64 MB ( 4009000)
: k' X6 [1 F/ P2 _5. [at 6d7c5000] 56 MB ( 389b000)" g6 j/ m5 Y) g2 y* e
6. [at 62c29000] 50 MB ( 3207000)1 v7 c9 W& m* U* g1 _1 f) a
7. [at d330000] 44 MB ( 2ca0000)
% o; A5 F8 F5 x& p$ o8. [at 663dd000] 41 MB ( 2983000), R% j9 d4 R) e- v" [0 G3 ^+ y3 B
9. [at 60809000] 36 MB ( 2417000)
9 F ]4 N, \$ P- e- w' g8 ?10. [at 5adf7000] 35 MB ( 2379000)1 d- z9 v' }' g3 P: y2 `9 S/ D
======= ==========. i# |) a: I- H$ r0 c7 a: V5 ]4 ~
1385 MB (569d4000)
对Vista系统,可能是因为我在第四步设置了命令3GB switche:可用最大虚拟内存是3G
>> feature('memstats')
. @* v6 u, A$ r _- P
% P( Q# R9 k- z& \2 z- t' hPhysical Memory (RAM):
- s; c5 M- h0 n0 XIn Use: 1082 MB (43a3a000)
# N1 z/ W8 b* @Free: 1467 MB (5bb96000)( C! ?& r7 s) W: X# e9 N
Total: 2549 MB (9f5d0000)
/ O# G O: X6 V! KPage File (Swap space):8 M( v; C- {* x; l2 O+ x" X! t
In Use: 1227 MB (4cbe3000)/ N/ V. B- E# X$ z/ m0 D
Free: 5315 MB (14c36e000) x. N* ]% A3 R( K( v# f9 O- s' l
Total: 6543 MB (198f51000)# M' Q. G4 m- J/ e/ E
Virtual Memory (Address Space):
" l3 f2 i5 n1 x2 I1 `* O2 }" `& |# TIn Use: 501 MB (1f5bf000)+ k( L7 p7 n5 j4 i
Free: 2570 MB (a0a21000)
" F' m8 A3 \" r: M/ W5 x; pTotal: 3071 MB (bffe0000)# K, r: }( H8 u, i: \0 Q5 ]$ C
Largest Contiguous Free Blocks:
4 _7 \/ J9 ~0 [1. [at 1b010000] 1074 MB (432d0000)* @' b9 ^5 M6 P8 v g# k+ {0 a
2. [at 7fff0000] 1023 MB (3ff9c000), O# I! i- S+ X: y7 |
3. [at 5e302000] 227 MB ( e32e000)
' g: J6 k: G8 g' M4. [at 7c41b000] 50 MB ( 32d5000)
( f* w& Q: R) Y5. [at 6d857000] 30 MB ( 1e09000)0 a( F5 T" n; h
6. [at 6f66b000] 21 MB ( 1595000)
' c& |8 W! b% ], M7. [at 715c3000] 20 MB ( 149d000)
x0 @2 L7 {& e) F3 ?! \3 ^4 Z6 P8. [at 7a038000] 18 MB ( 12f8000)% Q: r J2 o% z% a! T3 j; F" v
9. [at 739a6000] 17 MB ( 114a000)0 N) V, c" e/ f# t3 K# ]5 |
10. [at 70c41000] 9 MB ( 94f000)# `1 V* p' x7 H2 B2 T& M# {+ h
======= ==========
+ S) `0 g% Z# |- c) a& j t8 v2494 MB (9be3b000)
2. 采用PACK: 试了不管用
: C: w8 F% C* x# v0 a6 l3. 条件允许的话采用64位系统:32位免谈
8 ]+ f% M- S2 C g" S: v4. 采用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。
& T- B/ k! ?5 ~' r* U2 i" x2 K
5. 优化程序,减少变量
5 n0 I# ]) x. h& O% i5 T0 `+ a
6. 如果必有必要,不要启动java虚拟机,采用matlab -nojvm启动
# q' e9 G* a+ P) K, N0 `; k' j7. 关闭Matlab Server
0 F% d, v9 ~! y- W5 b/ S+ y# c! ~. |; Z# n