matlab程序碰到out of memory的问题真是让人崩溃的一件事情,程序是别人的,不能做大的改动,只能想办法增加内存。别人总结的可用的方法有:
1. 增加虚拟内存:右击我的电脑—属性--高级--性能设置--高级--虚拟内存更改,按自己电脑的硬盘在自定义大小里设置数字,然后再按设置-确定,然后重启。否则更改无效。
对XP,我发现即使增大虚拟内存到4G, matlab可用虚拟内存仍只有2G。仍然out of memory.+ l7 y: J* \3 E
>> feature('memstats')
+ P7 t! g- Q6 b0 T9 t% M4 UPhysical Memory (RAM):# x8 {7 \/ u9 y X
In Use: 611 MB (26364000)) }8 \8 t1 h, d" Y& d
Free: 1428 MB (59418000)' C1 h: s u8 U3 H, c+ I) f* v
Total: 2039 MB (7f77c000)
3 v9 u# v! K% a; IPage File (Swap space):
# P, v2 I5 b" ZIn Use: 470 MB (1d628000)# h5 ]2 A2 Y0 i
Free: 4481 MB (118156000)
: @/ k7 g" d- b6 j' Q9 tTotal: 4951 MB (13577e000), H9 j( o+ T* g: G+ y5 p) |8 V" I
Virtual Memory (Address Space):
1 a5 }% [. D+ V& bIn Use: 400 MB (190d3000)4 x, ~' Y0 N) d8 h) ^
Free: 1647 MB (66f0d000) k5 C( l. p; u
Total: 2047 MB (7ffe0000)9 C& ^8 e! D/ Z5 c& I A9 w, ^! H1 f
Largest Contiguous Free Blocks:
# A7 f5 W l, Q1. [at 20017000] 675 MB (2a3f9000)* n a2 k( |2 {$ T
2. [at 4b033000] 253 MB ( fd8d000)1 z' V" |: ~3 S, R/ q
3. [at 18010000] 127 MB ( 7ff0000)' m, x, k: x! r7 ~: v% U: s
4. [at 68ff7000] 64 MB ( 4009000); ]5 F, e, }1 U% U
5. [at 6d7c5000] 56 MB ( 389b000)" G! E! q( N% o
6. [at 62c29000] 50 MB ( 3207000)9 E2 p* ^0 b, {6 n; i
7. [at d330000] 44 MB ( 2ca0000)4 u. E# U z1 g9 \8 |
8. [at 663dd000] 41 MB ( 2983000) B/ o3 ?0 ]# z
9. [at 60809000] 36 MB ( 2417000)
6 T) @7 h6 d/ f* |+ _# D10. [at 5adf7000] 35 MB ( 2379000)% ^2 k( u6 B. B( n2 t- A/ N
======= ==========# q4 C6 I& l3 _+ ?' G w
1385 MB (569d4000)
对Vista系统,可能是因为我在第四步设置了命令3GB switche:可用最大虚拟内存是3G
>> feature('memstats')
9 I) Z2 V" g! v. N/ Z$ Y
+ h( x4 A4 T" T. [Physical Memory (RAM):
2 }6 A6 @: Z9 m" z) [ K+ jIn Use: 1082 MB (43a3a000)
4 m4 Q# R. s. m3 aFree: 1467 MB (5bb96000)
. g3 G+ p& U* j# H2 TTotal: 2549 MB (9f5d0000); [! H$ e9 T% V- \1 d
Page File (Swap space):
" W( Y* z% E& ~In Use: 1227 MB (4cbe3000)
% b' R O: L( R: }# jFree: 5315 MB (14c36e000)/ d- W$ v& Q; ?. W
Total: 6543 MB (198f51000)
5 u$ r% c6 |) V- J% p0 W( m; eVirtual Memory (Address Space):; @' }$ i4 _3 U: } Z
In Use: 501 MB (1f5bf000)
- P6 _1 h( y6 b, n; SFree: 2570 MB (a0a21000)
6 o! T1 B7 ~. m2 c; ~: MTotal: 3071 MB (bffe0000)3 `, H. P3 E; h
Largest Contiguous Free Blocks:
0 ^: x& n# j/ e$ Z& k$ M1. [at 1b010000] 1074 MB (432d0000)4 M0 J* d' J" D3 m
2. [at 7fff0000] 1023 MB (3ff9c000)
4 m" e- w( z9 `: i4 K7 E( P9 g3. [at 5e302000] 227 MB ( e32e000)! E' y: s, V: \* v$ ?; d5 }8 C
4. [at 7c41b000] 50 MB ( 32d5000)
5 }9 U" b) [6 v5 @. Q5. [at 6d857000] 30 MB ( 1e09000)
' d; i% T& Z8 V, {, z" Q; k6. [at 6f66b000] 21 MB ( 1595000)
. K2 G8 I. P) Y4 h* R7. [at 715c3000] 20 MB ( 149d000)
4 @0 k5 t- V2 T0 E) `( w* h; `8. [at 7a038000] 18 MB ( 12f8000)
* _1 Q2 t! _% @2 F6 A9. [at 739a6000] 17 MB ( 114a000) |. M p& L# i- y, G
10. [at 70c41000] 9 MB ( 94f000)2 i g) ? z' y% ?! R8 F7 o
======= ==========' w* D) L( x" _2 y/ Z$ d4 a
2494 MB (9be3b000)
2. 采用PACK: 试了不管用
, s- g8 J' T7 Q- i' e" {3. 条件允许的话采用64位系统:32位免谈
6 N) N! A& x" r$ e, j: P" _$ S
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。
L D" u: U2 v4 E5 v! a
5. 优化程序,减少变量
3 d# R' }" h7 a& }7 z; D D
6. 如果必有必要,不要启动java虚拟机,采用matlab -nojvm启动
* X2 A9 O9 C9 m' b% E2 x4 q: f7. 关闭Matlab Server
1 V8 X& t! {+ L1 e
; {: _( w4 X1 X. ~% u4 g+ d