简体   繁体   English

调用DLL function性能开销?

[英]Call to DLL function performance overhead?

I'm in a situation when I will often call two DLL functions from other DLL, and I need those functions to be separate, as I call them in different places as well.我的情况是我经常从其他 DLL 调用两个 DLL 函数,我需要将这些函数分开,因为我也在不同的地方调用它们。 But since I'm often calling them together, does it make sense to create another DLL function that will call those two, to call it in places where I need to call them both?但是因为我经常把它们一起调用,创建另一个 DLL function 来调用这两个,在我需要调用它们的地方调用它是否有意义?

Possibly, yes, due to inlining .可能,是的,由于内联 Calling a DLL function is relatively cheap on modern processors (especially when it is often called and the cache is warm).调用 DLL function 在现代处理器上相对便宜(尤其是当它经常被调用并且缓存很热时)。 However, if the function last for a very short time, it can still add a significant overhead.但是,如果 function 持续的时间很短,它仍然会增加大量开销。 Adding a DLL function calling the two others in the same module can prevent a function call.添加 DLL function 调用同一模块中的其他两个可以防止 function 调用。 In some case, the inlining help the compiler to optimize the code further .在某些情况下,内联有助于编译器进一步优化代码 For example, the constant propagation is often an optimization that matters a lot in such a case.例如,在这种情况下,常量传播通常是一种非常重要的优化。 That being said, if the two functions are not related each other, the benefit should be small.话虽这么说,如果这两个功能彼此不相关,那么好处应该很小。

Note that this is a micro-optimization and its benefit should be relatively small in most cases.请注意,这是一个微优化,在大多数情况下它的好处应该相对较小。 If the frequency of DLL calls is very high, then it should be much better to redesign your code (eg. typically by working on data chunks, using an optimizing JIT).如果 DLL 调用的频率非常高,那么重新设计代码应该会好得多(例如,通常通过处理数据块,使用优化 JIT)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM