马科斯宏中的C ++深度宏... [英] C++ deep macros in macros in marcos...

查看:66
本文介绍了马科斯宏中的C ++深度宏...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,



我有经验的c#dev,但由于性能问题,我有一项任务是将一些算法移植到cpp中。虽然c#just-in-time编译器和优化努力工作5到9使我的沙箱干净,但我的整个生命日都很好而且闪亮,今天我遇到了cpp性能问题,我觉得缺乏低级/架构/编译器知识。



问题:

我有一些不同的级别方法,例如:A,B,C,D。其中A呼叫B多次。 B多次呼叫C,C多次呼叫D,依此类推。因此,当我开始为最深层次的方法编写宏时,一切都很好,性能也得到了提高。不要说我重写了D macro,然后重写了C macro(在其中调用了D macro),然后重写了B macro。每次写宏时性能都在提高。但是现在我写了一个宏,性能下降得如此之快,甚至比没有任何宏都做得更糟糕。



问题:

发生了什么?它是某种方法阻塞它从堆栈中走出来并且cpu启动他的非算法相关的东西来分配/复制内存来继续这个巨大的宏?在编写宏或如何解决这个问题或如何将数学相关算法最充分地移植到cpp时,有哪些提示或规则?



为什么不内联?

https://msdn.microsoft.com/en-us/library/z8y1yy88 .aspx [ ^ ]如果函数有一个变量参数列表,我就不能使用它们。

Hello,

I'm experienced c# dev, but I got a task to port some algorithms into cpp due to performance. While my whole life days were nice and shiny when c# just-in-time compiler and optimizations worked hard 5 to 9 to make my sandbox clean, today I faced cpp performance questions where I feel having lack of low-level/architecture/compiler knowledge.

The problem:
I have some different level methods for example: A, B, C, D. Where A is calling B many times. B is calling C many times, C is calling D many times and so on. So when I started writing macros for deepest level methods everything was nice and performance improved. Lest say I rewrote D macro, then rewrote C macro (which calls D macro in it self), then rewrote B macro. And performance was increasing each time I wrote macro. But now I wrote A macro and performance dropped so rapidly it even got worse than doing everything with no macros at all.

Question:
What's happening? Is it some sort of method choke where it goes out of stack and cpu starts his non-algorithm related stuff to allocate/copy memory to proceed this huge macro? What are the tips or rule of thumbs when writing macros or how to solve this problem or how to port math related algorithms to cpp most sufficiently?

Why not inline?
https://msdn.microsoft.com/en-us/library/z8y1yy88.aspx[^] says I can't use them if "The function has a variable argument list."

推荐答案

不要使用宏。使用__inline进行被调用函数的内联扩展。



对于变量参数,您可能需要定义多个重载 - 以满足您的不同需求。



如果您发布代码我们可以提供更具体的建议。
Don't use macros for this. Use __inline for inline expansion of the called function.

For variable arguments, you may need to define multiple overloads - to match your varying needs.

We could offer more specific advice if you post your code.


这篇关于马科斯宏中的C ++深度宏...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆