📄 lib0026.html
字号:
<html>
<META http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Chapter 3: High-Level Services</title>
<link rel="STYLESHEET" type="text/css" href="images/xpolecat.css">
<link rel="STYLESHEET" type="text/css" href="images/ie.content.books24x7.css">
</head>
<body >
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<td><div STYLE="MARGIN-LEFT: 0.15in;">
<a href="toc.html"><img src="images/teamlib.gif" width="62" height="15" border="0" align="absmiddle" alt="Team LiB"></a></div></td>
<td valign="top" class="v2" align="right"><div STYLE="MARGIN-RIGHT: 0.15in"><a href="LiB0025.html"><img src="images/previous.gif" width="62" height="15" border="0" align="absmiddle" alt="Previous Section"></a>
<a href="LiB0027.html"><img src="images/next.gif" width="41" height="15" border="0" align="absmiddle" alt="Next Section"></a>
</div></td></tr>
</table>
<div class="chapter">
<a name="ch03"></a>
<h1 class="chapter-title"><span class="chapter-titlelabel">Chapter 3: </span>High-Level Services</h1><a name="291"></a><a name="IDX-127"></a>
<blockquote class="blockquote">
<p class="first-para">"My problem is that I have been persecuted by an integer."</p>
<p class="last-para">— George A. Miller</p>
</blockquote>
<div class="section">
<h2 class="sect2-title">
<a name="292"></a><a name="ch03lev1sec1"></a>View from 10,000 Feet</h2>
<p class="first-para">A computer's memory management subsystem can be likened to a house. The foundation and plumbing are provided by the hardware. It is always there, doing its job behind the scenes; you just take it for granted until something breaks. The frame of the house is supplied by the operating system. The operating system is built upon the foundation and gives the house its form and defines its functionality. A well-built frame can make the difference between a shack and a mansion.</p>
<p class="para">It would be possible to stop with the operating system's memory management facilities. However, this would be like a house that has no furniture or appliances. It would be a pretty austere place to live in. You would have to sleep on the floor and use the bathroom outside. User space libraries and tools are what furnish the operating system with amenities that make it easier for applications to use and execute within memory. High-level services like these are what add utility to the house and give it resale value (see <a class="internaljump" href="#ch03fig01">Figure 3.1</a> on the following page).</p>
<div class="figure">
<a name="293"></a><a name="ch03fig01"></a><span class="figuremediaobject"><a href="images/fig156%5F01%5F0%2Ejpg" NAME="IMG_50" target="_parent"><img src="images/fig156_01.jpg" height="167" width="280" alt="Click To expand" border="0"></a></span>
<br style="line-height: 1">
<span class="figure-title"><span class="figure-titlelabel">Figure 3.1</span></span>
</div>
<p class="para">There are two ways that user applications can allocate memory: compiler-based allocation and heap allocation.</p>
<p class="para">We will spend this chapter analyzing both of these techniques.</p>
<p class="para">The first approach is supported, to various degrees, by the development environment that is being used. Not all compilers, and the languages they translate, are equal. You will see a graphic demonstration of this later on in the chapter.</p>
<a name="294"></a><a name="IDX-128"></a>
<p class="para">The second approach is normally implemented through library calls (i.e., like <span class="fixed">malloc ()</span> and <span class="fixed">free ()</span>) or by a resident virtual machine. Using this technique to implement memory management provides a way for storage allocation facilities to be decoupled from the development tools. For example, there are several different implementations of <span class="fixed">malloc ()</span> that can be used with the <span class="fixed">gcc</span> compiler. Some engineers even specialize in optimizing <span class="fixed">malloc ()</span> and offer their own high-performance <span class="fixed">malloc.tar.gz</span> packages as a drop-in replacement for the standard implementation.</p>
<p class="para">In order to help illustrate these two approaches, I will look at several development environments. This will give you the opportunity to see how different tools and libraries provide high-level services to user applications. We will be given the luxury of forgetting about the hardware details and be able to look at memory from a more abstract vantage point. I will begin by looking at relatively simple languages, like COBOL, and then move on to more sophisticated languages, like C and Java.</p>
<table border="0" cellspacing="0" cellpadding="0" class="note">
<tr>
<td valign="top" class="admon-check"></td><td valign="top" class="admon-title">Note </td><td valign="top" class="admon-body">
<p class="first-para">Some people prefer to classify memory allocation techniques in terms of whether they are <i class="emphasis">static</i> or <i class="emphasis">dynamic</i>. Static memory is memory that is reserved from the moment a program starts until the program exits. Static memory storage cannot change size. Its use and position relative to other application components is typically determined when the source code for the application is compiled.</p>
<p class="para">Dynamic memory is memory that is requested and managed while the program is running. Dynamic memory parameters cannot be specified when a program is compiled because the size and life span factors are not known until run time.</p>
<p class="para">While dynamic memory may allow greater flexibility, using static memory allows an application to execute faster because it doesn't have to perform any extraneous bookkeeping at runtime. In a production environment that supports a large number of applications, using <a name="295"></a><a name="IDX-129"></a>static memory is also sometimes preferable because it allows the system administrators to implement a form of load balancing. If you know that a certain application has a footprint in memory of exactly 2MB, then you know how many servers you will need to provide 300 instances of the application.</p>
<p class="last-para">I think that the static-versus-dynamic scheme makes it more complicated to categorize hybrid memory constructs like the stack. This is why I am sticking to a compiler-versus-heap taxonomy.</p>
</td>
</tr>
</table>
<a></a>
</div>
</div>
</div>
</div>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<td><div STYLE="MARGIN-LEFT: 0.15in;">
<a href="toc.html"><img src="images/teamlib.gif" width="62" height="15" border="0" align="absmiddle" alt="Team LiB"></a></div></td>
<td valign="top" class="v2" align="right"><div STYLE="MARGIN-RIGHT: 0.15in"><a href="LiB0025.html"><img src="images/previous.gif" width="62" height="15" border="0" align="absmiddle" alt="Previous Section"></a>
<a href="LiB0027.html"><img src="images/next.gif" width="41" height="15" border="0" align="absmiddle" alt="Next Section"></a>
</div></td></tr>
</table>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -