How to improve memory administration inside Matlab?

3 ビュー (過去 30 日間)
Marco
Marco 2013 年 11 月 13 日
回答済み: Philip Borghesani 2013 年 11 月 14 日
How do I have to re-initialize my Matlab R2013b session in order to free the memory and to reestablish the contiguous virtual address space as I found them after a fresh start of Matlab? I would like to obtain this by a script within my Matlab session. I do not want to quit MATLAB and use any automatic procedure to restart Matlab completely and asking it to continue automatically with works.
This is my present situation, freshly having started a new Matlab session: Maximum possible array: 732 MB (7.680e+08 bytes)
After doing some works with Matlab, just before getting produced an ‘out-of-memory’ error: Maximum possible array: 254 MB (2.664e+08 bytes)
I here tried to free the memory to my best knowledge not even knowing if any ‘mex’ functionality was in use, or if the figure configuration might produce any real impact:
clear all;
clear mex;
clear functions;
clf;
close;
Maximum possible array: 372 MB (3.896e+08 bytes)
Only restarting the Matlab session completely advances the situation completely, I receive again: Maximum possible array: 732 MB (7.680e+08 bytes)
I already expect from reading about ‘out-of-memory’ discussions, that my 32-bit Win XP OS should be claimed responsible, but: why can´t Matlab at startup just reserve (i.e. occupy) all the available memory (i.e. the total of 1.7 GB which is offered to it on my system upon opening the session, including the i.e. 732 MB block of contiguous virtual address space), and then administrate this memory itself? Am I missing how to force Matlab to do this (I am almost raw beginner to Matlab, so far only know in this context to start my session as ‘matlab –shield medium’, and the ‘clear’ and ‘close’ commands exactly as listed above, and the ‘pack’ command which to the beginning or end of that list didn´t affect things), or is Matlab itself not prepared for any further memory administration?
If not changing to 32-bit Linux or changing to a 64-bit PC with 64-bit MS Win, would you have any suggestions what else I could do inside Matlab itself to improve memory re-establishement, besides applying my presented “list of re-initialization commands”?

採用された回答

Philip Borghesani
Philip Borghesani 2013 年 11 月 14 日
The only other way to improve the situation is to adjust the amount of virtual address space XP (or other 32 bit windows OS) will give MATLAB. This is done differently on XP and Vista/Win7 and 8. See these links: Note Answer for more information on changing this configuration known on XP as the 3GB boot switch.
I will attempt to explain why it is this way and why MATLAB can't do anything about it. When Microsoft designed the memory allocators for 32 bit Windows back when a typical windows machine had 4MB memory the 32 bit address space was huge so it efficiently using all of it was not important. Memory for a program is managed by two algorithms one for small blocks and one for large block. Virtual address space (not memory) given to the small block manager is never return to the system (large block manager) until the application exits. This can effectively reduce the amount of memory that a program with widely varying memory usage patterns, like some MATLAB programs, can use to half of the virtual address space given to the application. 64 bit Windows has the same design but 64 bits means that until machines have more then 4 exabytes ram nobody will bump into it.
Because MATLAB interacts with a large number of external libraries including third party and user supplied ones (mex files) it is not possible to allocate all virtual address space to MATLAB and then replace standard allocator operations with custom ones. No unmodified libraries code would be able to run.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

製品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by