|
13 | 13 |
|
14 | 14 | % get available RAM |
15 | 15 | freebytes = stdlib.ram_free(); |
| 16 | + |
| 17 | +% get user set preference for memory limit |
| 18 | +s = settings; |
| 19 | +ws = s.matlab.desktop.workspace; |
| 20 | + |
| 21 | +% Check if the maximum array size limit is enabled |
| 22 | +if ws.ArraySizeLimitEnabled.ActiveValue |
| 23 | + limit_bytes = double(ws.ArraySizeLimit.ActiveValue) / 100 * stdlib.ram_total(); |
| 24 | +else |
| 25 | + limit_bytes = inf; % no limit set |
| 26 | +end |
| 27 | + |
| 28 | +limit_bytes = min(limit_bytes, freebytes); |
| 29 | + |
16 | 30 | % variable sizing |
17 | 31 | switch(myclass) |
| 32 | + case 'complex single', bits = 64; |
| 33 | + case 'complex double', bits = 128; |
18 | 34 | case {'single','int32','uint32'}, bits = 32; |
19 | 35 | case {'double','int64','uint64','float'}, bits = 64; |
20 | 36 | case {'int16','uint16'}, bits = 16; |
21 | 37 | case {'int8','uint8'}, bits = 8; |
22 | 38 | case {'logical','bool'}, bits = 1; |
23 | | - case {'string','char'}, bits = 8; % FIXME is this correct? |
| 39 | + case {'string','char'}, bits = 8; |
24 | 40 | otherwise, error('unhandled variable class: %s', myclass) |
25 | 41 | end |
26 | 42 |
|
27 | 43 | newSizeBytes = prod(newSize)*bits / 8; |
28 | 44 |
|
29 | | -OK = newSizeBytes < freebytes; |
| 45 | +OK = newSizeBytes < limit_bytes; |
30 | 46 |
|
31 | 47 | end |
32 | 48 |
|
|
0 commit comments