Allocating Memory for Data Storage

< BACK  NEXT >
[oR]

Before data is stored in a virtual address, data storage must be allocated to that address. In Windows NT/98/2000, data storage is allocated from the paging file, but in Windows CE data storage is allocated from the physical memory allocated to program execution. Data storage is always allocated in whole numbers of pages, and in Windows CE pages are either 1 KB or 4 KB, depending on theplatform and the CPU architecture. Typically a number of pages are allocated at the same time, and these allocations must always start on an "allocation boundary," which in Windows CE is typically a 64-KB boundary.

Applications can manage their memory allocations at the page level using VirtualAlloc and VirtualFree. This can be a tricky business, since the page size of devices may be different. For example, if you need to allocate 18KB of data storage, this would require 18 pages on a device with 1-KB pages and 5 pages on a device with 4-KB pages. Further, the allocation would need to start at a 64-KB allocation boundary, so either 46 KB (for a 1-KB page size device) or 44 KB (for a 4-KB page size device) of address space would remain unusable. The page size issue can be a problem even when you are targeting a single type of device most Windows CE devices use a 1-KB page, but emulation on a desktop PC usually has a 4-KB page.

The only situation that requires direct page-level memory allocation using VirtualAlloc and VirtualFree is when an application needs to allocate a large amount of contiguous data storage. Otherwise, an application should use the heap-based allocation techniques described later in this chapter, and so avoid page size and allocation boundary issues.


< BACK  NEXT >


Windows CE 3. 0 Application Programming
Windows CE 3.0: Application Programming (Prentice Hall Series on Microsoft Technologies)
ISBN: 0130255920
EAN: 2147483647
Year: 2002
Pages: 181

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net