多线程库性能Multithreaded Libraries Performance

单线程的 CRT 不再可用。The single-threaded CRT is no longer available. 本主题讨论如何从多线程库中获取最佳性能。This topic discusses how to get the maximum performance from the multithreaded libraries.

最大程度地提高性能Maximizing performance

多线程库的性能已增强,并且接近消除的单线程库的性能。The performance of the multithreaded libraries has been improved and is close to the performance of the now-eliminated single-threaded libraries. 对于这些需要更高性能的情况,提高了多种新功能。For those situations when even higher performance is required, there are several new features.

  • 利用独立流锁定,可以锁定流,然后使用直接访问流的 _nolock 函数Independent stream locking allows you to lock a stream and then use _nolock Functions that access the stream directly. 这允许在关键循环的外部提升锁定用法。This allows lock usage to be hoisted outside critical loops.

  • 每个线程区域设置可降低多线程方案的区域设置访问成本(请参阅 _configthreadlocale)。Per-thread locale reduces the cost of locale access for multithreaded scenarios (see _configthreadlocale).

  • 区域设置相关的函数(名称以 _l 结尾)将区域设置用作参数,并降低了大量成本(例如,printf、_printf_l、wprintf、_wprintf_l)。Locale-dependent functions (with names ending in _l) take the locale as a parameter, removing substantial cost (for example, printf, _printf_l, wprintf, _wprintf_l).

  • 公共代码页的优化将降低许多短操作的成本。Optimizations for common codepages reduce the cost of many short operations.

  • 定义 _CRT_DISABLE_PERFCRIT_LOCKS 将强制所有 I/O 操作采用单线程的 I/O 模型并使用函数的 _nolock 形式。Defining _CRT_DISABLE_PERFCRIT_LOCKS forces all I/O operations to assume a single-threaded I/O model and use the _nolock forms of the functions. 这使高度基于 I/O 的单线程应用程序能够获得更好的性能。This allows highly I/O-based single-threaded applications to get better performance.

  • 通过公开 CRT 堆句柄,您可以启用 CRT 堆的 Windows 低分片堆 (LFH),这将大大改进高度缩放的方案的性能。Exposure of the CRT heap handle allows you to enable the Windows Low Fragmentation Heap (LFH) for the CRT heap, which can substantially improve performance in highly scaled scenarios.

另请参阅See Also

CRT 库功能CRT Library Features