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)),可以直接将函数的返回值用作其他字符串函数的参数。

资源下载链接为: https://pan.quark.cn/s/5c50e6120579 在Android移动应用开发中,定位功能扮演着极为关键的角色,尤其是在提供导航、本地搜索等服务时,它能够帮助应用获取用户的位置信息。以“baiduGPS.rar”为例,这是一个基于百度地图API实现定位功能的示例项目,旨在展示如何在Android应用中集成百度地图的GPS定位服务。以下是对该技术的详细阐述。 百度地图API简介 百度地图API是由百度提供的一系列开放接口,开发者可以利用这些接口将百度地图的功能集成到自己的应用中,涵盖地图展示、定位、路径规划等多个方面。借助它,开发者能够开发出满足不同业务需求的定制化地图应用。 Android定位方式 Android系统支持多种定位方式,包括GPS(全球定位系统)和网络定位(通过Wi-Fi及移动网络)。开发者可以根据应用的具体需求选择合适的定位方法。在本示例中,主要采用GPS实现高精度定位。 权限声明 在Android应用中使用定位功能前,必须在Manifest.xml文件中声明相关权限。例如,添加<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />,以获取用户的精确位置信息。 百度地图SDK初始化 集成百度地图API时,需要在应用启动时初始化地图SDK。通常在Application类或Activity的onCreate()方法中调用BMapManager.init(),并设置回调监听器以处理初始化结果。 MapView的创建 在布局文件中添加MapView组件,它是地图显示的基础。通过设置其属性(如mapType、zoomLevel等),可以控制地图的显示效果。 定位服务的管理 使用百度地图API的LocationClient类来管理定位服务
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、付费专栏及课程。

余额充值