Dr. Dobb's Journal - October 2007 - (Page 35) state, or filled with a simple pattern—usually all NULLs. On most modern platforms, virtual memory is committed at least a page at a time (for example, a page occupies four kilobytes of virtual memory on most versions of Windows). Pages of memory left uninitialized can be decommitted by any component in a process, and no harm results unless the committed memory is actually needed by the component that originally committed it. The same virtual memory analyzer/watchdog component that monitors reserved virtual memory may be extended to make software components smart enough to not die from an out-ofmemory condition whenever committed, uninitialized memory is available. The analysis can involve tracking the pages of memory as “in use” or “not in use.” One way to tell whether a page is in use is to run a compression routine, such as the LZW algorithm, on the contents of the page. This can be done for each page tracked by your analyzer/watchdog component when an out-of-memory condition occurs and when reserved, uncommitted pages are unavailable. When all or part of a page is found to be initialized, the page can be considered in use. The analysis can also involve recording a timestamp, during the run, each time virtual memory pages are commit- ted. When virtual memory runs low, your other components might need your analyzer/watchdog component to decommit the uninitialized page with the oldest timestamp, so that the page can be reused as needed to keep your program running. Figures 1–5 show a way you could design a simple virtual memory analyzer/watchdog component that helps your program stay alive, at least long enough to get some diagnostic information out, if not longer. The idea is to track virtual memory as the various components in your program reserve or commit it. For this to work, you need code that intercepts the system calls that are responsible for reserving, committing, and freeing virtual memory. On some operating systems, such as Linux, the choice of which calls to intercept is straightforward: On Linux, virtual memory regions are created via calls to mmap() and released via calls to munmap(). On other operating systems, such as Windows, there’s no documented API function that’s responsible for creating all of the virtual memory regions for use by your process. However, there is an API function, VirtualAlloc(), which you can use to create some regions. If you debug into VirtualAlloc(), you’ll reach an exported function that’s called for most, if not all, of the regions your program creates. On current versions of Windows, including Vista and XP, this function is called NtAllocateVirtualMemory(). This function Program is running Detect freeing of virtual memory region Update list of tracked virtual memory regions to indicate region is free Free tracked timestamp(s) and call chain, if any were recorded for the region Program continues running Figure 2 Program is running Detect reservation and/or commitment of virtual memory region Region was unreserved by our out-of-memory condition or exception handler? (see Figure 4) Yes Protect region from read/write access Record call chain associated with reservation/ commitment of stolen region Update entry in list of tracked virtual memory regions to tag region as stolen No Record new entry in list of tracked virtual memory regions Virtual memory is reserved but not committed? Yes Record timestamp for region as a whole No Record a set of timestamps, one associated with each page in the region Record call chain associated with original page reservation/commitment Record call chain associated with original page reservation/commitment Program continues running Figure 1 October 2007 l www.ddj.com l Dr. Dobb’s Journal 35 http://www.codejock.com http://www.codejock.com http://www.ddj.com
Table of Contents Feed for the Digital Edition of Dr. Dobb's Journal - October 2007 Cover Contents Hmmmm Alia Vox Developer Diaries Developer’s Notebook AI: It’s OK Again! Conversations Visual Cryptography and Bit-Plane Complexity Segmentation Inside the Windows Vista Disk Encryption Algorithm Memory-Aware Components Software and the Core Description Process Logging In C++ Effective Concurrency The Agile Edge Swaine’s Flames Dr. Dobb's Journal - October 2007 Dr. Dobb's Journal - October 2007 - Cover (Page Cover1) Dr. Dobb's Journal - October 2007 - Cover (Page Cover2) Dr. Dobb's Journal - October 2007 - Cover (Page 1) Dr. Dobb's Journal - October 2007 - Cover (Page 2) Dr. Dobb's Journal - October 2007 - Cover (Page 3) Dr. Dobb's Journal - October 2007 - Contents (Page 4) Dr. Dobb's Journal - October 2007 - Contents (Page 5) Dr. Dobb's Journal - October 2007 - Hmmmm (Page 6) Dr. Dobb's Journal - October 2007 - Hmmmm (Page 7) Dr. Dobb's Journal - October 2007 - Hmmmm (Page 8) Dr. Dobb's Journal - October 2007 - Hmmmm (Page 9) Dr. Dobb's Journal - October 2007 - Alia Vox (Page 10) Dr. Dobb's Journal - October 2007 - Alia Vox (Page 11) Dr. Dobb's Journal - October 2007 - Developer Diaries (Page 12) Dr. Dobb's Journal - October 2007 - Developer Diaries (Page 13) Dr. Dobb's Journal - October 2007 - Developer’s Notebook (Page 14) Dr. Dobb's Journal - October 2007 - Developer’s Notebook (Page 15) Dr. Dobb's Journal - October 2007 - AI: It’s OK Again! (Page 16) Dr. Dobb's Journal - October 2007 - AI: It’s OK Again! (Page 17) Dr. Dobb's Journal - October 2007 - AI: It’s OK Again! (Page 18) Dr. Dobb's Journal - October 2007 - AI: It’s OK Again! (Page 19) Dr. Dobb's Journal - October 2007 - Conversations (Page 20) Dr. Dobb's Journal - October 2007 - Conversations (Page 21) Dr. Dobb's Journal - October 2007 - Visual Cryptography and Bit-Plane Complexity Segmentation (Page 22) Dr. Dobb's Journal - October 2007 - Visual Cryptography and Bit-Plane Complexity Segmentation (Page 23) Dr. Dobb's Journal - October 2007 - Visual Cryptography and Bit-Plane Complexity Segmentation (Page 24) Dr. Dobb's Journal - October 2007 - Visual Cryptography and Bit-Plane Complexity Segmentation (Page 25) Dr. Dobb's Journal - October 2007 - Visual Cryptography and Bit-Plane Complexity Segmentation (Page 26) Dr. Dobb's Journal - October 2007 - Visual Cryptography and Bit-Plane Complexity Segmentation (Page 27) Dr. Dobb's Journal - October 2007 - Visual Cryptography and Bit-Plane Complexity Segmentation (Page 28) Dr. Dobb's Journal - October 2007 - Visual Cryptography and Bit-Plane Complexity Segmentation (Page 29) Dr. Dobb's Journal - October 2007 - Inside the Windows Vista Disk Encryption Algorithm (Page 30) Dr. Dobb's Journal - October 2007 - Inside the Windows Vista Disk Encryption Algorithm (Page 31) Dr. Dobb's Journal - October 2007 - Inside the Windows Vista Disk Encryption Algorithm (Page 32) Dr. Dobb's Journal - October 2007 - Inside the Windows Vista Disk Encryption Algorithm (Page 33) Dr. Dobb's Journal - October 2007 - Memory-Aware Components (Page 34) Dr. Dobb's Journal - October 2007 - Memory-Aware Components (Page 35) Dr. Dobb's Journal - October 2007 - Memory-Aware Components (Page 36) Dr. Dobb's Journal - October 2007 - Memory-Aware Components (Page 37) Dr. Dobb's Journal - October 2007 - Memory-Aware Components (Page 38) Dr. Dobb's Journal - October 2007 - Memory-Aware Components (Page 39) Dr. Dobb's Journal - October 2007 - Memory-Aware Components (Page 40) Dr. Dobb's Journal - October 2007 - Memory-Aware Components (Page 41) Dr. Dobb's Journal - October 2007 - Software and the Core Description Process (Page 42) Dr. Dobb's Journal - October 2007 - Software and the Core Description Process (Page 43) Dr. Dobb's Journal - October 2007 - Software and the Core Description Process (Page 44) Dr. Dobb's Journal - October 2007 - Software and the Core Description Process (Page 45) Dr. Dobb's Journal - October 2007 - Software and the Core Description Process (Page 46) Dr. Dobb's Journal - October 2007 - Software and the Core Description Process (Page 47) Dr. Dobb's Journal - October 2007 - Software and the Core Description Process (Page 48) Dr. Dobb's Journal - October 2007 - Software and the Core Description Process (Page 49) Dr. Dobb's Journal - October 2007 - Logging In C++ (Page 50) Dr. Dobb's Journal - October 2007 - Logging In C++ (Page 51) Dr. Dobb's Journal - October 2007 - Logging In C++ (Page 52) Dr. Dobb's Journal - October 2007 - Logging In C++ (Page 53) Dr. Dobb's Journal - October 2007 - Logging In C++ (Page 54) Dr. Dobb's Journal - October 2007 - Logging In C++ (Page 55) Dr. Dobb's Journal - October 2007 - Logging In C++ (Page 56) Dr. Dobb's Journal - October 2007 - Effective Concurrency (Page 57) Dr. Dobb's Journal - October 2007 - Effective Concurrency (Page 58) Dr. Dobb's Journal - October 2007 - Effective Concurrency (Page 59) Dr. Dobb's Journal - October 2007 - The Agile Edge (Page 60) Dr. Dobb's Journal - October 2007 - The Agile Edge (Page 61) Dr. Dobb's Journal - October 2007 - The Agile Edge (Page 62) Dr. Dobb's Journal - October 2007 - The Agile Edge (Page 63) Dr. Dobb's Journal - October 2007 - Swaine’s Flames (Page 64) Dr. Dobb's Journal - October 2007 - Swaine’s Flames (Page Cover3) Dr. Dobb's Journal - October 2007 - Swaine’s Flames (Page Cover4)
For optimal viewing of this digital publication, please enable JavaScript and then refresh the page. If you would like to try to load the digital publication without using Flash Player detection, please click here.