📄 424-428.html
字号:
<!-- end of ITK left NAV -->
<!-- begin main content -->
<td width="100%" valign="top" align="left">
<!-- END SUB HEADER -->
<!--Begin Content Column -->
<FONT FACE="Arial,Helvetica" SIZE="-1">
To access the contents, click the chapter and section titles.
</FONT>
<P>
<B>Essential Windows CE Application Programming</B>
<FONT SIZE="-1">
<BR>
<I>(Publisher: John Wiley & Sons, Inc.)</I>
<BR>
Author(s): Robert Burdick
<BR>
ISBN: 0471327476
<BR>
Publication Date: 03/01/99
</FONT>
<P>
<form name="Search" method="GET" action="http://search.earthweb.com/search97/search_redir.cgi">
<INPUT TYPE="hidden" NAME="Action" VALUE="Search">
<INPUT TYPE="hidden" NAME="SearchPage" VALUE="http://search.earthweb.com/search97/samples/forms/srchdemo.htm">
<INPUT TYPE="hidden" NAME="Collection" VALUE="ITK">
<INPUT TYPE="hidden" NAME="ResultTemplate" VALUE="itk-simple-intrabook.hts">
<INPUT TYPE="hidden" NAME="ViewTemplate" VALUE="view.hts">
<font face="arial, helvetica" size=2><b>Search this book:</b></font><br>
<INPUT NAME="queryText" size=50 VALUE=""> <input type="submit" name="submitbutton" value="Go!">
<INPUT type=hidden NAME="section_on" VALUE="on">
<INPUT type=hidden NAME="section" VALUE="http://www.itknowledge.com/reference/standard/0471327476/">
</form>
<!-- Empty Reference Subhead -->
<!--ISBN=0471327476//-->
<!--TITLE=Essential Windows CE Application Programming//-->
<!--AUTHOR=Robert Burdick//-->
<!--PUBLISHER=John Wiley & Sons, Inc.//-->
<!--IMPRINT=Wiley Computer Publishing//-->
<!--CHAPTER=16//-->
<!--PAGES=424-428//-->
<!--UNASSIGNED1//-->
<!--UNASSIGNED2//-->
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="421-424.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="428-432.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
<P><BR></P>
<P>The <I>dwTotalPageFile</I> and <I>dwAvailPageFile</I> members will always be zero. This is because Windows CE does not use a page file.</P>
<BLOCKQUOTE>
<P><FONT SIZE="-1"><HR><B>NOTE: </B><B>N<SMALL>O</SMALL> P<SMALL>AGE</SMALL> F<SMALL>ILE</SMALL> S<SMALL>UPPORT UNDER</SMALL> W<SMALL>INDOWS</SMALL> CE</B>
<P><B>Unlike Windows NT, Windows CE does not use a page file to manage virtual memory.</B><HR></FONT>
</BLOCKQUOTE>
</P>
<P><FONT SIZE="+1"><B><I>The</I> GetStoreInformation <I>Function
</I></B></FONT></P>
<P>The function <I>GetStoreInformation</I> returns the current state of object store memory:</P>
<!-- CODE SNIP //-->
<PRE>
GetStoreInformation(lpsi);
</PRE>
<!-- END CODE SNIP //-->
<P><I>lpsi</I> is a pointer to a STATUS_INFORMATION structure. This structure contains two DWORD members. The first is <I>dwStoreSize</I>, which <I>GetStoreInformation</I> uses to return the total size of the object store. The second, <I>dwFreeSize</I>, returns the amount of the total not currently in use.</P>
<P>The application MEMORY.EXE includes options under the Memory menu for displaying the memory status using <I>GlobalMemoryStatus</I> and <I>GetStoreInformation</I>. For example, the Physical Memory Status option displays the total and available physical device memory (Figure 16.1). Object Store Status displays the status of the object store memory (Figure 16.2).</P>
<P><A NAME="Fig1"></A><A HREF="javascript:displayWindow('images/16-01.jpg',654,245 )"><IMG SRC="images/16-01t.jpg"></A>
<BR><A HREF="javascript:displayWindow('images/16-01.jpg',654,245)"><FONT COLOR="#000077"><B>Figure 16.1</B></FONT></A> Physical Memory Status display.</P>
<P><A NAME="Fig2"></A><A HREF="javascript:displayWindow('images/16-02.jpg',654,245 )"><IMG SRC="images/16-02t.jpg"></A>
<BR><A HREF="javascript:displayWindow('images/16-02.jpg',654,245)"><FONT COLOR="#000077"><B>Figure 16.2</B></FONT></A> Object Store Memory Status display.</P>
<P><FONT SIZE="+1"><B><I>The</I> GetSystemInfo <I>Function
</I></B></FONT></P>
<P>A final system status function, <I>GetSystemInfo</I>, is useful for obtaining global memory information about a connected Windows CE device. Of particular interest to us here is that this function returns the virtual memory page size, as well as the highest and lowest memory addresses accessible to applications and dynamic link libraries.</P>
<P>The function syntax is:</P>
<!-- CODE SNIP //-->
<PRE>
GetSystemInfo(lpSystemInfo);
</PRE>
<!-- END CODE SNIP //-->
<P><I>lpSystemInfo</I> is a pointer to a SYSTEM_INFO structure. For example, an application might use this function as follows to display system diagnostics to the user:</P>
<!-- CODE //-->
<PRE>
SYSTEM_INFO si;
TCHAR pszText[257];
memset(&si, 0, sizeof(si));
GetSystemInfo(&si);
wsprintf(pszText, TEXT("Page Size: %d\nMax Address: %ld\nMin
Address: %ld"), si.dwPageSize,
si.lpMinimumApplicationAddress,
si. lpMaximumApplicationAddress);
MessageBox(NULL, pszText, TEXT("System Info"), MB_OK);
</PRE>
<!-- END CODE //-->
<P><FONT SIZE="+1"><B>Windows CE Application Address Space</B></FONT></P>
<P>In the previous section we saw that the Windows CE address space breaks about half of shared virtual application address space into 33 process slots of 32 MB each. Each application running on a Windows CE device occupies one of these slots.
</P>
<P>Slot 0 is reserved for the currently active process. As users switch between applications, the current application is swapped into slot 0. There can therefore be a maximum of 32 applications running at any one time.</P>
<P>The practical implication of this architectural detail is that each running Windows CE application can only access the virtual memory within its 32 MB slot. This limitation can be overcome through the use of memory mapped files, which are discussed later.</P>
<H3><A NAME="Heading4"></A><FONT COLOR="#000077">Allocating Memory</FONT></H3>
<P>An application can allocate virtual memory (as long as there is virtual memory available within its 32 MB slot boundary). It can allocate memory from its default heap, or create new heaps. Finally, applications can use stack memory.
</P>
<P>Each Windows CE thread has its own stack. Whenever a thread declares a variable, the memory to store the contents of that variable comes from the thread’s stack. Parameters passed to a function call are also placed on the stack.</P>
<TABLE BORDER="2" BORDERCOLOR="#0000" ALIGN="CENTER">
<TR><TD><FONT SIZE="+1"><B>Can You Say “Code Bloat”?</B></FONT>
<P>Not too long ago, a total of 32 MB of RAM on a desktop PC was more than enough for even a serious Windows NT workstation. Software development tools, word processors, e-mail packages, and a Web browser could all run at the same time on such a machine with no serious limitations.
</P>
<P>It is now common for even a low-priced PC to come equipped with 64 MB or more of RAM. One implication of this, other than greater application execution speed, is that applications can get larger, more complex, and handle ever larger amounts of data.</P>
<P>A similar trend is emerging in the world of Windows CE devices. Originally, Windows CE devices were designed as simple desktop companions for carrying phone numbers, addresses, and the like with you when away from your computer. Today, Windows CE devices are growing more complex and beginning to more closely resemble the desktop computers that Windows CE hoped to get away from.</P>
<P>The new Jupiter platform, for example, is used to produce Windows CE devices that are like pared-down laptop computers, with greater memory budgets and screen real estate than previous generation devices such as the handheld PC.</P>
<P>As this trend continues, I would expect the design of Windows CE to change such that the 32 MB application virtual memory limit is removed. As applications grow more complex, programmers will expect to have full access to the 2 GB virtual address space they are used to working with under Windows NT. And consumers will start asking themselves why they don’t just buy that laptop instead.</P>
</TABLE>
<P>The next sections cover Windows CE virtual memory and heaps in more detail.
</P>
<P><FONT SIZE="+1"><B>Virtual Memory</B></FONT></P>
<P>Windows CE uses a paged virtual memory model. Page sizes vary depending on the processor used by the particular Windows CE device. The size of a page can be determined by calling the <I>GetSystemInfo</I> API discussed earlier.</P>
<P>As is the case under Windows NT, virtual memory pages under Windows CE can be committed, reserved, or free. <I>Committed</I> means that physical memory has been allocated for the memory in question. <I>Reserved</I> means that the range of memory addresses corresponding to the virtual memory in question has been set aside for an application; however, no physical memory has yet been allocated. Finally, pages that are <I>free</I> are not committed or reserved, and therefore any application can allocate them.</P>
<P>A page of virtual memory can be allocated by an application by calling the <I>VirtualAlloc</I> function:</P>
<!-- CODE SNIP //-->
<PRE>
VirtualAlloc(lpAddress, dwSize, flAllocationType, flProtect);
</PRE>
<!-- END CODE SNIP //-->
<P>If successful, <I>VirtualAlloc</I> returns the base address of the allocated region of virtual memory pages. Otherwise it returns NULL.</P>
<P><I>lpAddress</I> specifies the starting address of the region of memory to allocate. This parameter can be NULL, in which case Windows CE determines where to start.</P>
<P><I>dwSize</I> indicates the number of bytes of virtual memory to be allocated. Like Windows NT, Windows CE will round this value up to the nearest page boundary. Therefore, if the size you specify is even one byte over a page limit, the entire next virtual memory page will be allocated for your application.</P><P><BR></P>
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="421-424.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="428-432.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
<!-- all of the reference materials (books) have the footer and subfoot reveresed -->
<!-- reference_subfoot = footer -->
<!-- reference_footer = subfoot -->
<!-- BEGIN SUB FOOTER -->
<br><br>
</TD>
</TR>
</TABLE>
<table width="640" border=0 cellpadding=0 cellspacing=0>
<tr>
<td align="left" width=135><img src="/images/white.gif" width=100 height="1" alt="" border="0"></td>
<!-- END SUB FOOTER -->
<!-- all of the books have the footer and subfoot reveresed -->
<!-- reference_subfoot = footer -->
<!-- reference_footer = subfoot -->
<!-- FOOTER -->
<td width="515" align="left" bgcolor="#FFFFFF">
<font face="arial, helvetica" size="1"><b><a href="/products.html"><font color="#006666">Products</font></a> | <a href="/contactus.html"><font color="#006666">Contact Us</font></a> | <a href="/aboutus.html"><font color="#006666">About Us</font></a> | <a href="http://www.earthweb.com/corporate/privacy.html" target="_blank"><font color="#006666">Privacy</font></a> | <a href="http://www.itmarketer.com/" target="_blank"><font color="#006666">Ad Info</font></a> | <a href="/"><font color="#006666">Home</font></a></b>
<br><br>
Use of this site is subject to certain <a href="/agreement.html">Terms & Conditions</a>, <a href="/copyright.html">Copyright © 1996-1999 EarthWeb Inc.</a><br>
All rights reserved. Reproduction whole or in part in any form or medium without express written permision of EarthWeb is prohibited.</font><p>
</td>
</tr>
</table>
</BODY>
</HTML>
<!-- END FOOTER -->
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -