{"id":2420,"date":"2009-05-08T11:17:17","date_gmt":"2009-05-08T11:17:17","guid":{"rendered":"https:\/\/blogs.mathworks.com\/pick\/2009\/05\/08\/is-your-memory-fragmented-what-can-you-do-about-it\/"},"modified":"2009-05-08T11:17:17","modified_gmt":"2009-05-08T11:17:17","slug":"is-your-memory-fragmented-what-can-you-do-about-it","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/pick\/2009\/05\/08\/is-your-memory-fragmented-what-can-you-do-about-it\/","title":{"rendered":"Is your memory fragmented? What can you do about it?"},"content":{"rendered":"<div xmlns:mwsh=\"https:\/\/www.mathworks.com\/namespace\/mcode\/v1\/syntaxhighlight.dtd\" class=\"content\">\r\n   <introduction>\r\n      <p>Want to know? Then download <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/2962\">Stuart McGarrity<\/a>'s <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/13548-chkmem\">CHKMEM<\/a> submission!\r\n      <\/p>\r\n   <\/introduction>\r\n   <p><a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/911\">Brett<\/a>'s Pick this week helps you determine if your memory is fragmented, and, more importantly, what steps you might take to minimize\r\n      'Out of Memory' errors. Many of you know of Stuart from the MATLAB Central File Exchange; for years, when we tracked these\r\n      things, he was the most-downloaded author on the Exchange. Those of us who know him as a colleague at The MathWorks know him\r\n      as well as a guru of sorts for dealing with memory (and out-of-memory) issues.\r\n   <\/p>\r\n   <p>Suppose you wanted to know the size of the largest variable you could create at any given moment in MATLAB. We know from the\r\n      <a href=\"https:\/\/www.mathworks.com\/help\/releases\/R2009a\/techdoc\/ref\/memory.html\">documentation<\/a> for the <tt>MEMORY<\/tt> command that the largest possible variable is the <i>smaller<\/i> of the following two values: a)The largest contiguous memory block found in the MATLAB virtual address space, and b) The\r\n      total available system memory. (The MEMORY command will return this value in a field called MaxPossibleArrayBytes.) Stuart's\r\n      file <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/13548-chkmem\">CHKMEM<\/a> takes MATLAB's memory command and does it one better. CHKMEM compares the largest available variable size to your system's\r\n      RAM and provides suggestions for decreasing the gap between the two. It also suggests ways to increase the available physical\r\n      memory. For instance, I had thought that my 3-GB switch was enabled; Stuart's code informed me that, in fact, it is not currently\r\n      set. And then he provides links to documentation showing how to set it!\r\n   <\/p>\r\n   <p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/pick\/chkmem.png\"> <\/p>\r\n   <p>Very nice utility, Stuart! Thanks for sharing it.<\/p>\r\n   <p>Comments? Share them <a href=\"https:\/\/blogs.mathworks.com\/pick\/?p=2420#respond\">here<\/a>.\r\n   <\/p><script language=\"JavaScript\">\r\n<!--\r\n\r\n    function grabCode_e3b3a46df43241e6a9a48be4280216a5() {\r\n        \/\/ Remember the title so we can use it in the new page\r\n        title = document.title;\r\n\r\n        \/\/ Break up these strings so that their presence\r\n        \/\/ in the Javascript doesn't mess up the search for\r\n        \/\/ the MATLAB code.\r\n        t1='e3b3a46df43241e6a9a48be4280216a5 ' + '##### ' + 'SOURCE BEGIN' + ' #####';\r\n        t2='##### ' + 'SOURCE END' + ' #####' + ' e3b3a46df43241e6a9a48be4280216a5';\r\n    \r\n        b=document.getElementsByTagName('body')[0];\r\n        i1=b.innerHTML.indexOf(t1)+t1.length;\r\n        i2=b.innerHTML.indexOf(t2);\r\n \r\n        code_string = b.innerHTML.substring(i1, i2);\r\n        code_string = code_string.replace(\/REPLACE_WITH_DASH_DASH\/g,'--');\r\n\r\n        \/\/ Use \/x3C\/g instead of the less-than character to avoid errors \r\n        \/\/ in the XML parser.\r\n        \/\/ Use '\\x26#60;' instead of '<' so that the XML parser\r\n        \/\/ doesn't go ahead and substitute the less-than character. \r\n        code_string = code_string.replace(\/\\x3C\/g, '\\x26#60;');\r\n\r\n        author = 'Brett Shoelson';\r\n        copyright = 'Copyright 2009 The MathWorks, Inc.';\r\n\r\n        w = window.open();\r\n        d = w.document;\r\n        d.write('<pre>\\n');\r\n        d.write(code_string);\r\n\r\n        \/\/ Add author and copyright lines at the bottom if specified.\r\n        if ((author.length > 0) || (copyright.length > 0)) {\r\n            d.writeln('');\r\n            d.writeln('%%');\r\n            if (author.length > 0) {\r\n                d.writeln('% _' + author + '_');\r\n            }\r\n            if (copyright.length > 0) {\r\n                d.writeln('% _' + copyright + '_');\r\n            }\r\n        }\r\n\r\n        d.write('<\/pre>\\n');\r\n      \r\n      d.title = title + ' (MATLAB code)';\r\n      d.close();\r\n      }   \r\n      \r\n-->\r\n<\/script><p style=\"text-align: right; font-size: xx-small; font-weight:lighter;   font-style: italic; color: gray\"><br><a href=\"javascript:grabCode_e3b3a46df43241e6a9a48be4280216a5()\"><span style=\"font-size: x-small;        font-style: italic;\">Get \r\n            the MATLAB code \r\n            <noscript>(requires JavaScript)<\/noscript><\/span><\/a><br><br>\r\n      Published with MATLAB&reg; 7.8<br><\/p>\r\n<\/div>\r\n<!--\r\ne3b3a46df43241e6a9a48be4280216a5 ##### SOURCE BEGIN #####\r\n%% Is your memory fragmented? What can you do about it?\r\n% Want to know? Then download\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/2962 Stuart McGarrity>'s\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/13548-chkmem CHKMEM> submission! \r\n\r\n%%\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/911 Brett>'s Pick this week helps you determine if your memory is fragmented, and, more importantly, what steps you might take to minimize 'Out of Memory' errors.\r\n% Many of you know of Stuart from the MATLAB Central File Exchange; for years, when we tracked these things, he was the most-downloaded author on the Exchange.\r\n% Those of us who know him as a colleague at The MathWorks know him as well as a guru of sorts for dealing with memory (and out-of-memory) issues.\r\n\r\n%%\r\n% Suppose you wanted to know the size of the largest variable you\r\n% could create at any given moment in MATLAB. We know from the\r\n% <https:\/\/www.mathworks.com\/help\/releases\/R2009a\/techdoc\/ref\/memory.html documentation> for the |MEMORY| command that the largest possible\r\n% variable is the _smaller_ of the following two values: a)The largest contiguous\r\n% memory block found in the MATLAB virtual address space, and b)\r\n% The total available system memory. (The MEMORY command will\r\n% return this value in a field called MaxPossibleArrayBytes.)\r\n% Stuart's file <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/13548-chkmem CHKMEM> \r\n% takes MATLAB's memory command and does it one better. CHKMEM\r\n% compares the largest available variable size to your system's\r\n% RAM and provides suggestions for decreasing the gap between the\r\n% two. It also suggests ways to increase the available physical\r\n% memory. For instance, I had thought that my 3-GB switch was enabled; Stuart's code informed me that, in fact, it is not currently set. And then he provides links to documentation showing how to set it!\r\n\r\n%%\r\n% \r\n% <<chkmem.png>>\r\n% \r\n\r\n%% \r\n% Very nice utility, Stuart! Thanks for sharing it.\r\n\r\n%%\r\n% Comments? Share them\r\n% <https:\/\/blogs.mathworks.com\/pick\/?p=2420#respond here>.\r\n##### SOURCE END ##### e3b3a46df43241e6a9a48be4280216a5\r\n-->","protected":false},"excerpt":{"rendered":"<p>\r\n   \r\n      Want to know? Then download Stuart McGarrity's CHKMEM submission!\r\n      \r\n   \r\n   Brett's Pick this week helps you determine if your memory is fragmented, and, more importantly, what... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/pick\/2009\/05\/08\/is-your-memory-fragmented-what-can-you-do-about-it\/\">read more >><\/a><\/p>","protected":false},"author":34,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[16],"tags":[],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/2420"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/users\/34"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/comments?post=2420"}],"version-history":[{"count":0,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/2420\/revisions"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/media?parent=2420"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/categories?post=2420"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/tags?post=2420"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}