设置内存管理器

来源:互联网 发布:360网络联盟 编辑:程序博客网 时间:2024/04/28 17:12
 
设置最小块对齐
  1. Use the function GetMinimumBlockAlignment to fetch the current minimum block alignment.
  2. Select the appropriate memory block alignment for your application. Available block alignments are 8-byte (mba8byte) and 16-byte (mba16byte).
  3. To change the memory block alignment, use the procedure SetMinimumBlockAlignment.
Note: Memory allocated through the Memory Manager is guaranteed to be aligned to at least 8-byte boundaries. 16-byte alignment is useful when memory blocks will be manipulated using SSE instructions, but may increase the memory usage overhead.


报告内存泄漏
  1. Set the global variable ReportMemoryLeaksOnShutdown to True.
  2. When the Memory Manager shuts down, it scans the memory pool and report all unregistered memory leaks in a message dialog. To register and unregister expected memory leaks, use the RegisterExpectedMemoryLeak and UnregisterExpectedMemoryLeak procedures.
Note: The Memory Manager can report memory that was allocated but not freed at the time the Memory Manager shuts down. Such memory blocks are called memory leaks and are often the result of programming errors. The default value for ReportMemoryLeaksOnShutdown is False

The class of a leak is determined by examining the first dword in the block. The reported classes of leaks may not always be 100% accurate. A leak is reported as a string leak if it appears to be an AnsiString. If the Memory Manager is unable to estimate the type of leak, it will be reported as belonging to the unknown class.


竟争条件下线程永不休眠
  1. Set the global variable NeverSleepOnMMThreadContention to True.
  2. When a thread contention occurs inside the Memory Manager, it will wait inside a loop until the contention is resolved.
Note: The Memory Manager is a shared resource, and when many threads in the application attempt to perform a Memory Manager operation at the same time, one or more threads might have to wait for a pending operation in another thread to complete before it can continue. This situation is called thread contention. When a thread contention occurs inside the Memory Manager, the default behavior is to relinquish the remaining time in the thread’s time slice. If the resource is still not available when the thread enters its next time slice, the Memory Manager calls the OS procedure Sleep to force it to wait longer (roughly 20 milliseconds) before trying again.  

This behavior works well on machines with single or dual core CPUs, and also when the ratio of the number of running threads to number of CPU cores is relatively high (greater than 2:1). In other situations, better performance can be obtained by entering a busy waiting loop until the resource becomes available. If NeverSleepOnMMThreadContention is True

, the Memory Manager will enter a wait loop instead of scheduling out. The default value for NeverSleepOnMMThreadContention is False.

原创粉丝点击