Apply a large-capacity physical memory under WinCE

xiaoxiao2021-03-06  117

reference from: http: //www.chinabyte.com/SoftChannel/72342371878043648/20040909/1852224.shtml [Article] Author: Fu Linlin Time: 2004-09-09 Source: NEW YORK Editor: Ark [article REVIEW] The physical memory of the application is not difficult, and the large capacity here refers to the physical memory of dozens of MB or more.

[Text] Applying for a large-capacity physical memory does not look hard. The large capacity here refers to physical memory for dozens of MB or even more. For C programmers, it may usually be accustomed to using the "New" operator. Me, too. Using "New" is very simple, you only need to judge whether the returned pointer is empty after the application. In other Windows operating systems, it does not need to consider excessive consideration on the application of large-capacity physical memory. But it is different on Windows CE. If you only use "new" to get it, it will be too affordable.

I don't know if I have encountered this situation under Windows CE. If you use the "New" application for more than 30MB physical memory, then the return must be empty (NULL), and even the program will die without a response. This is actually not surprising. In the series of "Windows CE Process, Thread and Memory Management", I have earlier, the Windows CE has a 32MB address space, although the SLOT 1 slot stores all non-Xip DLLs, but we can't take up Slot 1 slot. After 32MB address space minus the necessary code segments, static data segments, default stacks, and default stacks, the remaining address space is less than 32MB. Even if the program does not make any application requirements for more than 30MB of address space. So returning is very normal. Most of the software running under Windows CE does not require so many physical memory.

It feels that Microsoft's technology is not supported in the future, but has passed, as long as it meets the current and not far-reaching demand. For Platform Builder, the Imgram64 environment variable is used to support 64MB of physical memory. However, there is no IMGRAM128 or IMGRAM256 or even IMGRAM512. It may be that most of the Windows CE-based products have no more than 64MB of physical memory. Now support more than 64MB of physical memory, you must do some modifications. If you use "New" to use "New", it is only limited to 32MB. If you want new, how much is new, that's more cool!

"New" is not because the address space is not enough, then we can use virtual memory allocation, then submit this method of physical memory. In theory, it is actually not. For example, as follows:

LPVOID G_ADDRESS1, G_ADDRESS2;

g_address1 = Virtualalloc (0, 32 * 1024 * 1024, MEM_RESERVE, PAGE_NOACCESS); g_address2 = Virtualalloc (g_address1, 32 * 1024 * 1024, mem_commit, page_readwrite);

The first statement in this section is the application 32MB virtual address space, and the function returns an address description application is successful. Note that this address must be in 0x4200 million (see "Windows CE processes, threads and memory management (3)"). The second statement is to submit physical memory with a capacity of 32MB. This function returns NULL indicating that the application is unsuccessful. If the application is 10MB, 20MB can be applied.

I hope to break again. The final method is that the memory mapped file. Only the memory map file can be used to apply for a virtual address space in the Help document for Windows CE. Can try it. The results prove that the memory map file is used to apply a large-capacity physical memory is feasible. When the memory map file is used for multiple processes to share data, the first parameter of the function that creates a memory map must be set to INVALID_HANDLE_VALUE, which is created in physical memory. With this feature we can apply for more than 32MB of physical memory. The specific size can be applied is determined by the remaining physical memory. The examples are as follows: #define maxlen (64 * 1024 * 1024) Handle Hfile; hfile = createfilemapping (invalid_handle_value, null, page_readwrite, 0, maxlen, null); if (hfile == null) {/// creation file mapping object failed Return LPVOID LPADDRESS; LPADDRESS = MapViewOffile (HFILE, FILE_MAP_WRITE | File_Map_read, 0, 0, Maxlen); if (lpaddress == null) {/// creation file view failed Return;}

If the above functions are successful, you can use physical memory. The first address of the virtual memory is LPAddress. Used, don't forget the call function unmapViewoffile (LPADDRESS); and CloseHandle (HFILE);

转载请注明原文地址:https://www.9cbs.com/read-99110.html

New Post(0)