matlab程序碰到out of memory的问题真是让人崩溃的一件事情,程序是别人的,不能做大的改动,只能想办法增加内存。别人总结的可用的方法有:
1. 增加虚拟内存:右击我的电脑—属性--高级--性能设置--高级--虚拟内存更改,按自己电脑的硬盘在自定义大小里设置数字,然后再按设置-确定,然后重启。否则更改无效。
对XP,我发现即使增大虚拟内存到4G, matlab可用虚拟内存仍只有2G。仍然out of memory.
( a/ {& T8 _1 F, X; z5 x
>> feature('memstats')
$ D. }7 q. V. p* q- dPhysical Memory (RAM):. |8 R9 h' |4 o# g
In Use: 611 MB (26364000) M) Y, d. q$ W/ X6 ~6 M
Free: 1428 MB (59418000)! V& L- y" h |3 ]. G/ [9 ]
Total: 2039 MB (7f77c000)
2 q: ~. p1 U% ~9 l% P9 o" wPage File (Swap space):
1 V! e9 ?( s s3 aIn Use: 470 MB (1d628000), ]8 Q* E( [$ g: ]- S6 `& w
Free: 4481 MB (118156000)0 E7 P# X. B7 N3 M9 W
Total: 4951 MB (13577e000)9 G' p. r( V8 v* K! z# @
Virtual Memory (Address Space):
+ ^ U% v7 K6 x4 i* A0 J' QIn Use: 400 MB (190d3000)
3 s- ^5 Y7 S* N2 VFree: 1647 MB (66f0d000)0 X/ p) n' _7 n" [7 V# \5 f
Total: 2047 MB (7ffe0000)
& w4 j& J: b1 u$ P1 k" d; z$ ^Largest Contiguous Free Blocks:
$ d8 x l# ]0 P. X1. [at 20017000] 675 MB (2a3f9000), [: F4 A& R8 B+ @* Y) V
2. [at 4b033000] 253 MB ( fd8d000)5 S% c; n) U! Z
3. [at 18010000] 127 MB ( 7ff0000)
4 {& s, P8 I+ g4. [at 68ff7000] 64 MB ( 4009000)* D+ l0 E6 n+ H$ i: v5 [% v l$ u
5. [at 6d7c5000] 56 MB ( 389b000)
5 y3 g8 p" i+ N, i- k! c6. [at 62c29000] 50 MB ( 3207000)
# j6 q+ X. y2 M, G. A. j# ~' t) g2 |7. [at d330000] 44 MB ( 2ca0000): V u; u, Y( f f5 j# C
8. [at 663dd000] 41 MB ( 2983000)! ]) |9 Y! F. }' O) ^1 i
9. [at 60809000] 36 MB ( 2417000)
. k7 L- I* G S* K10. [at 5adf7000] 35 MB ( 2379000)
5 i8 |5 j* b) O; e5 i6 ]======= ==========
- |! f' V# ~" r2 X" |& D1385 MB (569d4000)
对Vista系统,可能是因为我在第四步设置了命令3GB switche:可用最大虚拟内存是3G
>> feature('memstats')
8 k' }) V% O( h; k& I0 M; g4 z) F/ |+ l: m
Physical Memory (RAM):
* N' B9 p. P: f4 g* Z/ kIn Use: 1082 MB (43a3a000)
, C* \$ C! S. W$ s/ wFree: 1467 MB (5bb96000)
' Z; `# V( m3 E; ~8 zTotal: 2549 MB (9f5d0000)
3 o4 |; {$ j. G4 Y* B1 X% IPage File (Swap space):2 T8 \4 A$ g$ G: F" l' R6 s0 ]4 L
In Use: 1227 MB (4cbe3000). A- n- r8 p8 Z+ _% e
Free: 5315 MB (14c36e000)) ^$ R1 K8 {& H/ T& f% F
Total: 6543 MB (198f51000)3 f' _! v; ^0 i3 v/ @) @
Virtual Memory (Address Space):2 B) r8 x, j# ~+ m* n6 I
In Use: 501 MB (1f5bf000)
8 X* k1 ~5 c5 q+ r3 u0 i5 }Free: 2570 MB (a0a21000)" r* j& e; l. t( V* p$ o; B% m- z
Total: 3071 MB (bffe0000)# J9 W ^3 B% e! ?0 C
Largest Contiguous Free Blocks:) b3 q1 _# @5 p# n. r# I0 A( c6 l
1. [at 1b010000] 1074 MB (432d0000); T/ @& X% m. N
2. [at 7fff0000] 1023 MB (3ff9c000)2 L$ \$ `6 ^1 }" V
3. [at 5e302000] 227 MB ( e32e000)$ z b+ E) v% U* E( E3 r; g
4. [at 7c41b000] 50 MB ( 32d5000)7 s( a* Q" ]3 s3 [" j- U. M. C
5. [at 6d857000] 30 MB ( 1e09000)) [; y/ u$ B1 j0 Q& M
6. [at 6f66b000] 21 MB ( 1595000)3 w% J% F$ D$ _; J. {! N6 Q- L
7. [at 715c3000] 20 MB ( 149d000)
# D6 \) Q8 }% ^( y7 X8. [at 7a038000] 18 MB ( 12f8000)
+ h8 p r+ ]* E* ?0 f3 s+ a9 e9. [at 739a6000] 17 MB ( 114a000)6 z6 q I* W. Q& A* G1 H' r3 T
10. [at 70c41000] 9 MB ( 94f000)
# Z; ?* t b F _0 j# d5 M- D8 M======= ==========
8 G& T6 |% o' _8 \! l" G( b2494 MB (9be3b000)
2. 采用PACK: 试了不管用
/ m0 X7 ~7 f; v5 K( k3. 条件允许的话采用64位系统:32位免谈
$ Z9 a1 x. P+ S7 T
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。
, o# A& U. H9 Y7 S+ e" O; x
5. 优化程序,减少变量
. U5 b% m) t6 X* M6. 如果必有必要,不要启动java虚拟机,采用matlab -nojvm启动
8 J5 t p4 {$ S& F
7. 关闭Matlab Server
) \. R3 }6 R @! p% c
7 {3 Z3 S4 r4 ] N! w8 V1 i$ o& I/ C