使用 Boost Date Time Library 和 Visual Studio 2008 时运行时检查失败

发布于 2024-10-06 23:53:54 字数 567 浏览 8 评论 0原文

我是计算机科学专业一年级的学生,正在编写一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

回忆追雨的时光 2024-10-13 23:53:54

这看起来像是一个调用约定问题,但看起来它实际上是一个结构成员对齐问题。

您必须在客户端代码中使用默认的结构成员对齐方式。在项目属性中,选择配置属性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 the Structure Member Alignment options is set to Default.

See here for another question about this problem.

空心↖ 2024-10-13 23:53:54

我对 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文