这篇文章是继文章Windows Embedded CE 6.0 Internals (1)的。内存这块不停是让人头痛的器械，由于对照繁杂，然则我们却必要常常与其打交道——内存透露、非常定位、法度榜样优化等等。这篇文章以及后续的文章我试着能够刨根问底。
1.Random Access Memory (RAM)
Random access memory can be read or written directly at any address. There are various types of RAM that are differentiated by the underlying hardware technology used to implement them. However they all share the ability to be read or written directly at any random address. RAM memory is volatile, the contents are only maintained as long as power is not lost.
2.Read Only Memory (ROM)
Read Only Memory typically refers to memory that can be read just like RAM, but not written directly. Most ROM used today can be rewritten using a software algorithm, and is often called Flash ROM. Data stored in ROM is nonvolatile, and remains valid even after power is removed. ROM is sometimes used to refer to any kind of memory that is nonvolatile, even if it is not randomly acce澳门威泥斯人ssible (e.g. paged memory).
Some memory technologies are not randomly accessible. These memory technologies must be read and written in blocks. A CPU typically requires memory that it executes code from to be randomly accessible, so Paged memory can’t be used as a medium to execute code. This type of memory is often used for bulk nonvolatile storage, and includes NAND technology.(存储在NAND Flash中的镜像在履行时被拷贝到RAM中。而NOR Flash是支持XIP的，这也是NAND和NOR的主要差别。)
Windows Embedded CE 6.0应用单一的32位(4G)平坦模式虚拟内存寻址空间。
下图是Windows CE 5.0的4GB虚拟内存散播图，每个进程零丁的内存是32MB，当前系统最多只容许存在32个进程。
下图是Windows Embedded CE 6.0的4GB虚拟内存散播图，每个进程现在都有2GB的虚拟地址，扬弃了原本的按Slot分配的要领，而是只要你必要你就可以创建内存。关于更具体的请见下面的内核态和用户态地址空间。
▲CPU Specific VM
▲Kernel VM(if supported by CPU)256 MB
▲Kernel VM256 MB
▲Object Store128 MB
▲Kernel XIP DLLs128 MB
▲Static Mapped Uncached512 MB
▲Static Mapped Cached512 MB
▲Shared System Heap255 MB
▲RA澳门威泥斯人M Backed Mapfiles256 MB
RAM backed map files are memory mapped file objects that do not have an actual file underneath them. This region provides backward compatibility for applications that used RAM-backed map files for cross-process communication, expecting all processes to map views at the same virtual address. Every process that opens the same RAM backed memory mapped file will get the same pointer value. File backed memory mapped file澳门威泥斯人s will be allocated from the virtual memory area of the process, and differ for each process.
▲Shared User DLLs512 MB
When a process initializes, the OS maps the following DLLs and memory components: DLLs and ROM DLL read/write sections are loaded bottom up starting at 1GB. DLLs are controlled by the loader, which loads all the DLLs at the same address for each process.
▲Process Space1024 MB
The stack, the heap, and the executable (.exe) file are created and mapped from the bottom up starting at 64KB. Virtual memory allocations occur in the first 1GB after the executable code and data. The bottom 64 KB of memory always remains free.
▲Local Heap (Default)
Each application has a default, or local, heap created by the OS when an application launches. By default, Windows Embedded CE 6.0 initially reserves 64 KB of virtual memory for the local heap, but only commits the pages as they are allocated. If the application allocates more than the 64 KB in the local heap, the system allocates more virtual memory by using VirtualAlloc to fulfill the request for memory. (第一次系统默认给利用法度榜样堆的大年夜小事64K，当跨越这个大年夜小时，系统应用VirtualAlloc分配更多的内存来满意你的需求。)
An application can also create any number of separate heaps. These private heaps have the same properties as the local heap but are managed through a separate set of heap functions. You can specify the maximum or initial size when creating private heaps.(这系列堆函数是HeapCreate, HeapAlloc, HeapFree, HeapReAlloc, HeapSize等。)
Shared heaps allow for efficient data transfer from kernel mode components to user processes. Shared heaps are writeable to kernel components, and read only to user processes. Shared heaps are located in a system wide area at the top of the user address space, and visible to all user processes. Therefore you should not put any sensitive data in a shared heap.(上图用户态地址空间中血色部分等于，它对付内核是可读的，但对用户态进程是只读的。)
Remote heaps are a new feature of WindowsCE Embedded 6.0. A remote heap allows a server and client process to share memory safely. The server process creates and has full access to the remote heap, while the client process can read and optionally write to it. The client process can’t destroy the heap metadata.(为了更好的满意客户端/办事器端通信而孕育发生的。)
Storage area for variables referenced in a program.
下图是Windows Mobile 6.0 Prefessional模拟器的堆截图：
Each process has at least one heap, with the HF32_DEFAULT flag. This is the local heap that is created for every process. Notice some processes have more heaps (unnamed), these are private heaps that the process chose to create. Fixed means they are in use. Free means that they can be reused. BigBlock is a region of memory that was allocated outside the heap due to its size. Notice that BigBlock areas are created on 64KB boundaries, that is the granularity of the low level memory allocation APIs.(内存分配的粒度是64K，这是编程时应该留意的问题，认真会造成内存挥霍。)
安装了Platform Builder插件的Visual Studio 2005 SP1可以从Target->Target Control打开Windows CE敕令提示符窗口。在敕令提示符后键入'mi’即可以看到内核和零丁进程的内存信息。比如mi ["kernel","full"], kernel代表列出内核内存具体信息，full代表列出整个内存信息。
A blank space indicates a virtual page that is not currently allocated. Does not require a physical page.
-Reserved but not in use. Indicates a virtual page that is currently allocated but not mapped to any physical memory. Does not require a physical page.
CCode pages in ROM. Does not require a physical page.
cCode pages in RAM. Requires a physical page.
SIndicates a virtual page that holds a stack. Requires a physical page.
PPeripheral memory (pages used to map target device memory by using VirtualAlloc). Indicates a virtual page that is used to map a range of hardware addresses. Does not require a physical page. Peripheral memory may include frame buffer memory.
WIndicates a virtual page that holds read-write data. Requires a physical page. Read-write pages include global variables as well as dynamically allocated memory.
OIndicates a virtual page that is used by the object store. Requires a physical page. Should only appear in the Filesys process.
rRead-only data pages in RAM. Requires a physical page. Read-only data primarily comes from data items that are declared as a const type in the source code.
RRead-only data pages in ROM. Does not require a physical page. Read-only data primarily comes from data items that are declared as a const type in the source code.
Note: For CPUs such as ARM and SHx that do not distinguish between read-only and executable code pages in hardware, use R(r) to represent both data and code.