Some design tradeoffs

1,为什么STL stack的pop操作返回值类型是void,而不直接返回栈顶元素,用一个pop同时搞定top和pop两个函数的工作岂不是更加优雅高效?

SGI的解释:

One might wonder why pop() returns void, instead of value_type. That is, why must one usetop() andpop() to examine and remove the top element, instead of combining the two in a single member function? In fact, there is a good reason for this design. Ifpop() returned the top element, it would have to return by value rather than by reference: return by reference would create a dangling pointer. Return by value, however, is inefficient: it involves at least one redundant copy constructor call. Since it is impossible forpop() to return a value in such a way as to be both efficient and correct, it is more sensible for it to return no value at all and to require clients to usetop() to inspect the value at the top of the stack.

简言之,当pop返回时,根据语义,栈顶元素已经出栈了,此时不能再返回一个引用,而必须将栈顶元素以传值的方式返回,需要至少构造一个临时对象,影响效率。虽然有NRV优化的存在,但是一方面不能完全依赖编译器,另一方面NRV优化在Stan Lippman看来必须要有Copy constructor存在。

另一个观点是,如果stack中存放的是复杂的类型,在copy constructor的过程中发生异常,则临时对象就会丢失,这牵涉到thread safety的一些讨论,关于此问题的一些相关信息:

http://www.sgi.com/tech/stl/stack.html

http://www.gotw.ca/gotw/008.htm

http://stackoverflow.com/questions/4892108/c-stl-stack-question-why-does-pop-not-throw-an-exception-if-the-stack-is-em

 

2,关于itoa函数的设计问题。首先给出itoa的原型:
char *_itoa(
    int value,
    char *str,
int radix
);
为什么要在两个地方返回结果?其实最后一个参数str既是传入参数也是传出参数,它指向的是调用者预分配好的空间,itoa假定这个空间足够大(这也就是为啥这个函数不安全的原因,假如str指向的空间不够大,就溢出了,所以_itoa_s需要强制指定str指向的空间大小,并在函数内部检查确保不溢出)。
之所以将结果字符串同时也通过返回值返回,我猜测是便于方便这样调用:strlen(_itoa(100, str, 10)),可以直接将函数的返回值用作其他字符串函数的参数。

1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看REAdMe.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看REAdMe.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看READme.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。
1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 、 1资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看READmE.文件(md如有),本项目仅用作交流学习参考,请切勿用于商业用途。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。
Simultaneous, on-chip FPGA delay measurement is a powerful technique for characterizing the performance of FPGA designs. However, there are several pitfalls and tradeoffs that must be considered when using this technique. One pitfall is the potential for measurement errors due to coupling between measurement signals and other signals on the FPGA. This coupling can lead to inaccurate measurements and must be carefully controlled through proper design techniques. Another tradeoff is the tradeoff between measurement accuracy and measurement speed. More accurate measurements require longer measurement times, which can impact overall system performance. Therefore, it is important to carefully balance measurement accuracy and measurement speed to obtain the best overall system performance. Additionally, the choice of measurement technique can also impact the accuracy and speed of on-chip FPGA delay measurement. For example, pulse width measurement techniques may be faster but less accurate than time interval measurement techniques. Finally, the choice of measurement circuitry can also impact the accuracy and speed of on-chip FPGA delay measurement. Careful consideration must be given to the design of the measurement circuitry to ensure accurate and reliable measurements. Overall, simultaneous, on-chip FPGA delay measurement is a powerful technique for characterizing FPGA designs, but careful consideration must be given to the potential pitfalls and tradeoffs to obtain accurate and reliable measurements.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值