使用 Boost Date Time Library 和 Visual Studio 2008 时运行时检查失败
我是计算机科学专业一年级的学生,正在编写一个 C++ 程序,该程序对随机分配的浮点数组进行冒泡排序,然后使用二分查找来查找数组中最后一个元素的值(以保证代码计时时的一致性)。
我想对冒泡排序和二分查找的执行进行计时,但 C++ 标准时间库只会给我秒级精度,这是不可用的,因为此代码在大多数情况下执行时间不到 1 秒。
我找到了 Boost,并且尝试将其用作使用 Boost DateTime 库中的微秒时钟获得代码执行的亚秒级精确计时的方法。我使用的代码位于 http://pastebin.com/U8D0s2hb。当我执行此代码时,我从 Visual Studio 2008 中收到以下错误:
运行时检查失败#0 - ESP 的值未在函数调用中正确保存。这通常是用一种调用约定声明的函数和用另一种调用约定声明的函数指针调用的结果。
罪魁祸首似乎是将时间作为 ptime 对象获取,但我不知道为什么,因为我以前从未见过运行时检查失败错误。
任何帮助表示赞赏,谢谢。
I'm a first year computer science student, writing a c++ program that bubble sorts an array of randomly assigned floats and then uses a binary chop search to find the value of the last element in the array (for consistency while timing the code).
I want to time the execution of the bubble sorting and binary chop searching, but the c++ standard time library will only give me second level precision, which isn't usable as this code executes in under 1 second most of the time.
I have found Boost and I'm trying to use that as a way of getting a sub-second precision timing of the execution of code using the microsecond clock in the Boost DateTime library. The code I am using is at http://pastebin.com/U8D0s2hb. When I execute this code, I get the following error from Visual Studio 2008:
Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call. This is usually a result of calling a function declared with one calling convention with a function pointer declared with a different calling convention.
The culprit appears to be getting the time as a ptime object, but I have no idea why as I have never seen a runtime check failure error before.
Any help appreciated, thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这看起来像是一个调用约定问题,但看起来它实际上是一个结构成员对齐问题。
您必须在客户端代码中使用默认的结构成员对齐方式。在项目属性中,选择
配置属性
、C/C++
、代码生成
并确保结构成员对齐
选项设置为默认
。有关此问题的另一个问题,请参阅此处。
This looks like a calling convention problem, but it appears it's actually a structure member alignment issue.
You have to use the default structure member alignment in your client code. In your project's properties, select
Configuration Properties
,C/C++
,Code Generation
and ensure theStructure Member Alignment
options is set toDefault
.See here for another question about this problem.
我对 boost.thread 也有同样的问题。
我跟踪了更改历史记录,发现我添加了一个标头 <windows.h>在 <boost/thread.hpp> 之前。我怀疑也许 windows.h 标头定义了一些调用约定,这会混淆 boost/thread.hpp,所以我将 windows.h 文件放在 boost/thread.hpp 之后,问题就消失了。
希望这有帮助。
I had the same problem with boost.thread.
I tracked the change history and I found that I added a header <windows.h> before <boost/thread.hpp>. I suspected that maybe windows.h header defined some calling conventions which would confuse boost/thread.hpp, so I put windows.h file after boost/thread.hpp, and the problem disappeared.
Hope this helps.