DisableThreadLibraryCalls 的作用

第一篇文章

看Wince驱动时,看到Init函数时不时有这个函数,不知道啥意思,

BOOL DisableThreadLibraryCalls(
  HMODULE hLibModule
);

This function disables the DLL_THREAD_ATTACH and DLL_THREAD_DETACH notifications for the DLL specified by the hLibModule parameter.

Using this function can reduce the size of the working code set for some applications.

Remarks

Windows CE does not support static-thread local storage; therefore, the only restriction for specifying a DLL to disable is that it is a valid module.

The DisableThreadLibraryCalls function lets a DLL disable the DLL_THREAD_ATTACH and DLL_THREAD_DETACH notification calls.

This can be a useful optimization for multithreaded applications that have many DLLs, frequently create and delete threads, and whose DLLs do not need these thread-level notifications of attachment/detachment.

By disabling the notifications, the DLL initialization code is not paged-in because a thread is created or deleted, which reduces the size of the application's working code set.

Disabling the notification calls can be used for any DLL where there is no thread-level tracking required. If you need to track resources on a thread-by-thread basis, the notification should not be turned off.

To implement the optimization, modify a DLL's DLL_PROCESS_ATTACH code to call DisableThreadLibraryCalls.

Drivers that exist in the Device Manager Device.exe process space should call DisableThreadLibraryCalls if no thread-specific data is needed.

 

重点:

This can be a useful optimization for multithreaded applications that have many DLLs, frequently create and delete threads, and whose DLLs do not need these thread-level notifications of attachment/detachment.

该函数在有许多DLL,频繁创建和删除线程,并且DLL不需要线程级消息如DLL_THREAD_ATTACH and DLL_THREAD_DETACH时的多线程应用中是很有效的优化。

 

 

 

 

### Kernelbase.dll 加载性能优化方法 #### 背景分析 Kernelbase.dll 是 Windows 系统中的核心动态链接库之一,提供了许多基础的服务和支持功能。其稳定性和效率对于整个系统的正常运行至关重要[^1]。然而,在某些情况下,可能会遇到 kernelbase.dll 的加载速度较慢的问题。 为了提高 kernelbase.dll 的加载性能,可以从以下几个方面入手: --- #### 1. 减少线程附加/分离通知的影响 当多个线程被创建或销毁时,系统会自动调用 DllMain 中的 `DLL_THREAD_ATTACH` 和 `DLL_THREAD_DETACH` 事件处理程序。如果不需要这些回调操作,则可以通过调用 `DisableThreadLibraryCalls` API 来禁用它们。这可以减少不必要的开销并提升加载效率[^2]。 以下是实现该功能的一个简单代码示例: ```cpp #include <windows.h> BOOL DisableThreadNotifications(HMODULE hModule) { return DisableThreadLibraryCalls(hModule); } ``` 通过此方式,能够有效降低因频繁触发线程关联事件而导致的延迟。 --- #### 2. 更新操作系统补丁和驱动程序 确保所使用的 Windows 版本是最新的,并安装最新的安全更新和服务包。微软经常发布针对 kernelbase.dll 性能改进以及修复漏洞的相关补丁。保持系统最新状态有助于改善整体表现。 此外,过时或者不兼容的硬件驱动也可能间接影响到 kernelbase.dll 的工作效能,所以也需要定期检查并升级设备驱动至官方推荐版本。 --- #### 3. 使用预取技术(Prefetching) Windows 自带了一项名为 Superfetch 或 Prefetcher 的内存管理特性,它可以根据历史数据预测哪些文件会被再次访问并将它们提前缓存起来。虽然这项功能主要面向应用程序启动加速设计,但对于像 kernelbase.dll 这样广泛使用的组件同样适用。确认超级提取(SuperFetch)已启用可以帮助加快后续对该 dll 文件读取的速度。 要验证预制是否开启,请执行以下命令查看注册表设置: ```cmd reg query "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management\PrefetchParameters" /v EnableSuperfetch ``` 如果返回值为零表示关闭;将其改为一即可重新激活该项服务。 --- #### 4. 避免恶意软件干扰 有时病毒或其他形式的恶意软件可能篡改合法的 system files 如 kernelbase.dll ,从而引起异常行为包括但不限于加载时间延长等问题 。建议利用可靠的防毒工具进行全面扫描清除潜在威胁因素的同时也要注意备份重要资料以防万一发生不可逆损害情况的发生. --- #### 结论 综上所述, 可以采取多种措施来缓解 kernelbase.dll 加载缓慢的现象 , 包括合理运用编程接口控制资源消耗程度、维持良好的软硬环境匹配度以及加强网络安全防护意识等方面综合施策才能取得理想效果 . ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值