⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 free2os.es.html

📁 this is a mirrored site c-faq. thought might need offline
💻 HTML
字号:
<html><!-- Mirrored from c-faq.com/malloc/free2os.es.html by HTTrack Website Copier/3.x [XR&CO'2008], Sat, 14 Mar 2009 08:02:59 GMT --><head><title></title></head><body>From: Eric Sosman<br>Newsgroups: comp.lang.c,comp.lang.c++<br>Subject: Re: freed memory back to OS?<br>Date: Thu, 15 Apr 1999 08:24:08 +0100<br>Message-ID: &lt;37159418.D53AD8DE@acm.org&gt;<p>Dan &lt;dgadda@asu.edu&gt; wrote:<br>&gt; Is there a command to give back freed memory to the operating system?<br>&gt; Any suggestions would be very helpful.<p>I have written memory managers which released unused memory to theO/S (Unix, Windows, OpenVMS), and hindsight tells me it probably wasn'tworth the trouble.  Here's the crucial question: What benefit do youexpect to obtain by releasing the memory?<p>Observe that the amount of memory released must be sizable if it'sto make a noticeable difference in the overall performance of thecomputer: the O/S will not fall all over itself with gratitude if yougive up 8KB or so.  The O/S will also not benefit much if it gets itsmegabytes back a mere few moments before the program terminates; tenmegabyte-seconds is not a lot in the grand scheme of things.<p>So what does this imply about the nature of a program which canusefully release memory to the O/S?  It has to be a program which runsin ``phases'' of some sort, where a phase which needs a lot of memory isfollowed by a phase which needs substantially less memory but runs fora significant amount of time.  Such programs exist -- we can imagine,say, a program which manipulates a few 1000x1000 matrices to computea single value needed by later phases, but doesn't need to keep themulti-megabyte matrices around after the initial computation finishes.In my experience (admittedly non-exhaustive), such programs are prettyrare -- not non-existent (I'm not trying to start a war of anecdoteshere), but definitely the exception rather than the rule.<p>Keep in mind that allocated but unused memory is relatively cheapin a virtual memory O/S: if it's not referenced for a while it willmigrate to backing store and just chew up some space on a disksomewhere, but it won't prevent the O/S and other programs from gettingaccess to physical RAM.  Unless you're starved for backing store thiswon't make much difference -- and if backing store is really scarce,you probably have other problems, too.<p>There is one noticeable advantage to releasing memory rather thanretaining it in idleness: When you need it again, the O/S may be ableto just supply you a bunch of freshly-zeroed pages rather than carefullyretrieving megabytes of junk from the paging disk just so you can writeall over them.  Programs which can benefit from the ability to tell theO/S ``I no longer care about the data in this chunk of memory'' seem to befairly common, but the benefit is seldom enormous -- if it is enormous,many systems have (non-portable, but useful) ways to help out, but notusually in the framework of a general-purpose allocator.<p>The bottom line: Releasing memory is usually not all that helpful,and in situations where it might be there are usually other concernswhich would urge system-specific solutions anyhow.  IMHO, YMMV, etc.<p>-- <br>Eric Sosman</body><!-- Mirrored from c-faq.com/malloc/free2os.es.html by HTTrack Website Copier/3.x [XR&CO'2008], Sat, 14 Mar 2009 08:02:59 GMT --></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -