简体   繁体   English

非本地跳转是否存在性能问题?

[英]Are there performance problems with non-local jumps?

I am using non-local jumps ( setjmp , longjmp ). 我正在使用非本地跳转( setjmplongjmp )。 I would like to know if it can be a problem for the performances. 我想知道这是否会对演出造成影响。 Does setjmp save all the stack, or just some pointers ? setjmp保存所有堆栈还是仅保存一些指针?

Thanks. 谢谢。

setjmp has to save sufficient information for the program to continue execution when longjmp is called. setjmp必须保存足够的信息,以便在调用longjmp时程序可以继续执行。 This will typically consist of the current stack pointer, along with the current values of any other CPU registers that could affect the computation. 它通常由当前堆栈指针以及可能影响计算的任何其他CPU寄存器的当前值组成。

I can't comment on whether this causes a "performance problem", because I don't know what you want to compare it against. 我无法评论这是否会导致“性能问题”,因为我不知道您要与之进行比较。

The quick answer is: not very likely. 快速的答案是:不太可能。 If setjmp ever becomes a noticeable bottleneck in your program, I'd tend to say your program design needs an overhaul. 如果setjmp曾经成为您程序中的明显瓶颈,我倾向于说您的程序设计需要大修。

Like Jens said, if it ever becomes a noticeable bottleneck, redesign it since that is not how setjmp is supposed to be used. 就像Je​​ns所说的那样,如果它成为一个明显的瓶颈,请重新设计它,因为这不是应该使用setjmp方式。

As for your question: 至于你的问题:
This probably depends on which architecture you are running your program on and exactly what the compiler does with your code. 这可能取决于您在其上运行程序的体系结构以及编译器对代码的确切作用。 On ARM, goto is probably translated into a single branch instruction which is quite fast. 在ARM上, goto可能会转换为一条非常快的分支指令。 setjmp and longjmp on the other hand need to save and restore all registers in order to resume execution after the jump. 另一方面, setjmplongjmp需要保存和恢复所有寄存器,以便在跳转后恢复执行。 On an ARMv7-a with NEON support, this would require saving roughly 16 32-bit registers and up to 16 128-bit registers which is quite a bit of extra work compared to a simple branch. 在支持NEON的ARMv7-a上,这将需要保存大约16个32位寄存器和多达16个128位寄存器,与简单分支相比,这需要很多工作。

I have no idea if less work is required on x86, but I would suspect that goto is a lot cheaper there too. 我不知道在x86上是否需要较少的工作,但是我怀疑goto在那里也便宜很多。

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

相关问题 检查跳转缓冲区是否有效(非本地跳转) - Check if jump buffer is valid or not (non-local jumps) 即使存在非本地跳转,也可以稳健地检测递归 - Detect recursion robustly even in the presence of non-local jumps 非本地变量在C ++中使用匿名类型警告 - non-local variable uses anonymous type warning in C++ 转到标签上的“预期表达”错误(非本地转到) - “expected expression” error on goto label (non-local goto) 在 C 中进行清理的非本地退出的最佳实践? - Best practices for non-local exit with cleanup in C? 如何使Linux接受发往非本地地址的数据包? - How to get Linux accept packets destined to non-local addresses? Clang-Tidy:根据未初始化的非局部变量、C 指针引用,用非常量表达式初始化非局部变量 - Clang-Tidy: Initializing non-local variable with non-const expression depending on uninitialized non-local variable, C pointer reference 使用C-API的IBM MQ 7.5检查本地还是非本地集群队列 - IBM MQ 7.5 using C-API to check if local or non-local cluster queue 初始化为非本地指针后从函数返回指针 - Returning pointer from function after being initialized to non-local pointer 在setjmp.h中定义的C中的非本地跳转如何工作? - How does Non - local Jumps in C defined in setjmp.h work?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM