- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在我的库(替换全局 new
/delete
运算符)中,我使用另一个外部库(casablanca pplx)。此外部库不包含替换的 new
/delete
运算符(我使用 Visual Studio 的 showincludes 选项进行了检查)。
此外部库的某些对象(例如流或异常)是使用默认的new[]
运算符创建的(它调用我替换的 new
运算符),并使用默认的 delete[]
运算符销毁(它不会调用我替换的 delete
运算符)。这会导致一般保护故障。
什么可以解释这种行为?
我使用 Visual Studio 2012。
示例源代码(使用 casablanca http 客户端获取 google.fr):
web::http::client::http_client_config config;
config.set_timeout(std::chrono::seconds(10));
utility::string_t uri = L"http://www.google.fr";
web::http::client::http_client client(uri, config);
web::http::http_request request(web::http::methods::GET);
client.request(request).then([uri](web::http::http_response response ) {
unsigned short statusCode = response.status_code();
if (statusCode == 200)
{
concurrency::streams::stringstreambuf stream;
return response.body().read_to_end(stream).then([stream](size_t) {
std::string responseText = stream.collection();
}); // crash here (stream destructor)
}
});
新的调用堆栈:
Application64_d.dll!operator new(unsigned __int64 iSize) Line 262 C++ // My replaced new operator
Application64_d.dll!operator new[](unsigned __int64 count) Line 7 C++ // C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\crt\src\newaop.cpp
Application64_d.dll!Concurrency::streams::details::basic_producer_consumer_buffer<unsigned char>::_block::_block(unsigned __int64 size) Line 437 C++
Application64_d.dll!std::_Ref_count_obj<Concurrency::streams::details::basic_producer_consumer_buffer<unsigned char>::_block>::_Ref_count_obj<Concurrency::streams::details::basic_producer_consumer_buffer<unsigned char>::_block><unsigned __int64 & __ptr64>(unsigned __int64 & _V0) Line 873 C++
Application64_d.dll!std::make_shared<Concurrency::streams::details::basic_producer_consumer_buffer<unsigned char>::_block,unsigned __int64 & __ptr64>(unsigned __int64 & _V0) Line 972 C++
Application64_d.dll!Concurrency::streams::details::basic_producer_consumer_buffer<unsigned char>::_alloc(unsigned __int64 count) Line 165 C++
Application64_d.dll!Concurrency::streams::details::streambuf_state_manager<unsigned char>::alloc(unsigned __int64 count) Line 651 C++
Application64_d.dll!Concurrency::streams::streambuf<unsigned char>::alloc(unsigned __int64 count) Line 993 C++
Application64_d.dll!web::http::client::details::winhttp_client::completion_callback(void * hRequestHandle, unsigned __int64 context, unsigned long statusCode, void * statusInfo, unsigned long statusInfoLength) Line 1167 C++
winhttp.dll!00007ff83259db67() Unknown
winhttp.dll!00007ff83259d87a() Unknown
winhttp.dll!00007ff832599fe5() Unknown
Application64_d.dll!web::http::client::details::winhttp_client::read_next_response_chunk(web::http::client::details::winhttp_request_context * pContext, unsigned long bytesRead, bool firstRead) Line 693 C++
Application64_d.dll!web::http::client::details::winhttp_client::completion_callback(void * hRequestHandle, unsigned __int64 context, unsigned long statusCode, void * statusInfo, unsigned long statusInfoLength) Line 1156 C++
winhttp.dll!00007ff83259db67() Unknown
winhttp.dll!00007ff8325c653d() Unknown
Application64_d.dll!web::http::client::details::winhttp_client::completion_callback(void * hRequestHandle, unsigned __int64 context, unsigned long statusCode, void * statusInfo, unsigned long statusInfoLength) Line 1051 C++
winhttp.dll!00007ff83259db67() Unknown
winhttp.dll!00007ff8325a20b7() Unknown
winhttp.dll!00007ff8325958a0() Unknown
winhttp.dll!00007ff832594699() Unknown
ntdll.dll!00007ff839723021() Unknown
ntdll.dll!00007ff839721989() Unknown
kernel32.dll!00007ff8392c2774() Unknown
ntdll.dll!00007ff839750d51() Unknown
删除调用堆栈:
msvcr110d.dll!operator delete(void * pUserData) Line 52 C++ // C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\crt\src\dbgdel.cpp
msvcr110d.dll!operator delete[](void * p) Line 22 C++ // C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\crt\src\delete2.cpp
Application64_d.dll!Concurrency::streams::details::basic_producer_consumer_buffer<unsigned char>::_block::~_block() Line 443 C++
Application64_d.dll!Concurrency::streams::details::basic_producer_consumer_buffer<unsigned char>::_block::`scalar deleting destructor'(unsigned int) C++
Application64_d.dll!std::_Ref_count_obj<Concurrency::streams::details::basic_producer_consumer_buffer<unsigned char>::_block>::_Destroy() Line 885 C++
Application64_d.dll!std::_Ref_count_base::_Decref() Line 121 C++
Application64_d.dll!std::_Ptr_base<Concurrency::streams::details::basic_producer_consumer_buffer<unsigned char>::_block>::_Decref() Line 347 C++
Application64_d.dll!std::shared_ptr<Concurrency::streams::details::basic_producer_consumer_buffer<unsigned char>::_block>::~shared_ptr<Concurrency::streams::details::basic_producer_consumer_buffer<unsigned char>::_block>() Line 624 C++
Application64_d.dll!std::shared_ptr<Concurrency::streams::details::basic_producer_consumer_buffer<unsigned char>::_block>::`scalar deleting destructor'(unsigned int) C++
Application64_d.dll!std::allocator<std::shared_ptr<Concurrency::streams::details::basic_producer_consumer_buffer<unsigned char>::_block> >::destroy<std::shared_ptr<Concurrency::streams::details::basic_producer_consumer_buffer<unsigned char>::_block> >(std::shared_ptr<Concurrency::streams::details::basic_producer_consumer_buffer<unsigned char>::_block> * _Ptr) Line 624 C++
Application64_d.dll!std::allocator_traits<std::allocator<std::shared_ptr<Concurrency::streams::details::basic_producer_consumer_buffer<unsigned char>::_block> > >::destroy<std::shared_ptr<Concurrency::streams::details::basic_producer_consumer_buffer<unsigned char>::_block> >(std::allocator<std::shared_ptr<Concurrency::streams::details::basic_producer_consumer_buffer<unsigned char>::_block> > & _Al, std::shared_ptr<Concurrency::streams::details::basic_producer_consumer_buffer<unsigned char>::_block> * _Ptr) Line 758 C++
Application64_d.dll!std::_Wrap_alloc<std::allocator<std::shared_ptr<Concurrency::streams::details::basic_producer_consumer_buffer<unsigned char>::_block> > >::destroy<std::shared_ptr<Concurrency::streams::details::basic_producer_consumer_buffer<unsigned char>::_block> >(std::shared_ptr<Concurrency::streams::details::basic_producer_consumer_buffer<unsigned char>::_block> * _Ptr) Line 910 C++
Application64_d.dll!std::deque<std::shared_ptr<Concurrency::streams::details::basic_producer_consumer_buffer<unsigned char>::_block>,std::allocator<std::shared_ptr<Concurrency::streams::details::basic_producer_consumer_buffer<unsigned char>::_block> > >::pop_front() Line 1476 C++
Application64_d.dll!Concurrency::streams::details::basic_producer_consumer_buffer<unsigned char>::update_read_head(unsigned __int64 count) Line 644 C++
Application64_d.dll!Concurrency::streams::details::basic_producer_consumer_buffer<unsigned char>::read(unsigned char * ptr, unsigned __int64 count, bool advance) Line 620 C++
Application64_d.dll!<lambda_1f1656160f66eb3ff369c30cc6352caf>::operator()() Line 279 C++
Application64_d.dll!std::_Callable_obj<<lambda_1f1656160f66eb3ff369c30cc6352caf>,0>::_ApplyX<void>() Line 431 C++
Application64_d.dll!std::_Func_impl<std::_Callable_obj<<lambda_1f1656160f66eb3ff369c30cc6352caf>,0>,std::allocator<std::_Func_class<void,std::_Nil,std::_Nil,std::_Nil,std::_Nil,std::_Nil,std::_Nil,std::_Nil> >,void,std::_Nil,std::_Nil,std::_Nil,std::_Nil,std::_Nil,std::_Nil,std::_Nil>::_Do_call() Line 239 C++
Application64_d.dll!std::_Func_class<void,std::_Nil,std::_Nil,std::_Nil,std::_Nil,std::_Nil,std::_Nil,std::_Nil>::operator()() Line 514 C++
Application64_d.dll!Concurrency::streams::details::basic_producer_consumer_buffer<unsigned char>::_request::complete() Line 543 C++
Application64_d.dll!Concurrency::streams::details::basic_producer_consumer_buffer<unsigned char>::fulfill_outstanding() Line 424 C++
Application64_d.dll!Concurrency::streams::details::basic_producer_consumer_buffer<unsigned char>::_close_write() Line 360 C++
Application64_d.dll!Concurrency::streams::details::streambuf_state_manager<unsigned char>::close(int mode) Line 413 C++
Application64_d.dll!Concurrency::streams::streambuf<unsigned char>::close(int mode) Line 960 C++
Application64_d.dll!Concurrency::streams::basic_ostream<unsigned char>::close() Line 151 C++
Application64_d.dll!web::http::details::http_msg_base::_complete(unsigned __int64 body_size, const std::exception_ptr & exceptionPtr) Line 181 C++
Application64_d.dll!web::http::client::details::request_context::complete_request(unsigned __int64 body_size) Line 119 C++
Application64_d.dll!web::http::client::details::winhttp_client::completion_callback(void * hRequestHandle, unsigned __int64 context, unsigned long statusCode, void * statusInfo, unsigned long statusInfoLength) Line 1194 C++
winhttp.dll!00007ff83259db67() Unknown
winhttp.dll!00007ff83259d87a() Unknown
winhttp.dll!00007ff832599fe5() Unknown
Application64_d.dll!web::http::client::details::winhttp_client::read_next_response_chunk(web::http::client::details::winhttp_request_context * pContext, unsigned long bytesRead, bool firstRead) Line 693 C++
Application64_d.dll!web::http::client::details::winhttp_client::completion_callback(void * hRequestHandle, unsigned __int64 context, unsigned long statusCode, void * statusInfo, unsigned long statusInfoLength) Line 1231 C++
winhttp.dll!00007ff83259b6aa() Unknown
Application64_d.dll!web::http::client::details::winhttp_client::completion_callback(void * hRequestHandle, unsigned __int64 context, unsigned long statusCode, void * statusInfo, unsigned long statusInfoLength) Line 1174 C++
winhttp.dll!00007ff83259db67() Unknown
winhttp.dll!00007ff8325955e7() Unknown
winhttp.dll!00007ff832594699() Unknown
ntdll.dll!00007ff839723021() Unknown
ntdll.dll!00007ff839721989() Unknown
kernel32.dll!00007ff8392c2774() Unknown
ntdll.dll!00007ff839750d51() Unknown
新建和删除运算符:
inline void* operator new (::size_t size);
inline void operator delete (void* ptr);
inline void* operator new[] (::size_t size);
inline void operator delete[] (void* ptr);
最佳答案
在 Visual Studio 2013(及更早版本)中,默认的 delete[]
运算符不是内置在应用程序的二进制文件中(与默认的new
、new[]
和 delete
运算符)。它是直接从 msvcr110d.dll 调用的。
当使用inline关键字时,被替换的new[]
和delete[]
运算符在整个应用程序中不会被默认使用(与 new
和 delete
运算符相反),除非我们明确包含 header 。
因此,默认的 new[] 运算符(内置于应用程序的二进制文件中)调用替换的 new 运算符。
但默认的 delete[]
运算符(直接从 msvcr110d.dll 调用) 找不到替换的 delete
运算符并使用默认的 删除
运算符(来自msvcr110d.dll)。
对于我的解决方案,我删除了 inline 关键字并将运算符放入源文件中。
此错误已修复,不应出现在 Visual Studio 2015(及更新版本)中。
关于c++ - 新建/删除不匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45330453/
我目前正在开发自己的内存泄漏跟踪系统。 我正在使用 Microsoft Visual C++ 2008,我知道他们有一个内置的,但我一直在为自己制作一个,只是为了好玩。 但是,当我覆盖 new 和 n
在我的库(替换全局 new/delete 运算符)中,我使用另一个外部库(casablanca pplx)。此外部库不包含替换的 new/delete 运算符(我使用 Visual Studio 的
最近的 C++ 标准中的内存分配操作是否有复杂性保证?也就是说,如果我有一个类 A,其默认构造函数和析构函数在 O(1) 中运行,那么“new A[N]”和“delete[] A”的 big-O 是什
我正在用 Qt 和 C++ 编写一个简单的编辑器。我想要有标签,所以在创建新文档后,我想在新标签中打开它。我的代码: // mainwindow.cpp #include "mainwindow.h"
好吧,这让我感到困惑...下面的代码在一个 DLL 中,当我的控制台应用程序调用这段代码时,它突然在 delete[] lpBuffer 行抛出访问冲突。我整天都在使用这段代码,根本没有改变它。到目前
我现在很头疼。 基本上我有这个: Class A -> Class B Class A -> Class C Class A -> Class D Class E with constructor w
我想通过将一个表 (tableA) 与另一个表 (tableB) 进行比较来查找新的、修改的和删除的记录。两个表具有相同的模式并具有唯一的 ID 字段。 在我的情况下,tableA 最初与 table
这是我们的商业案例, 应用程序为使用过的 iPhone 提供即时报价,并允许卖家立即出售。另一方面,有些买家愿意立即购买或竞标房源。潜在的零售商可以访问网站并根据年份、型号、状况、配件输入获得即时报价
需要一些帮助。设法创建一个 jQuery 来在单击后更改按钮的类,但我需要您单击一个从其他按钮中删除的新按钮类。 我正在努力,但我做不到。我已经尝试了一些方法,但每当我尝试时,我都可以删除所有内容并单
为什么“创建 Java 项目”屏幕中有时会缺少“内容”部分(带有“从现有源创建项目”选项)?我知道我以前见过并使用过它,但现在它已经消失了。 最佳答案 您最好在 Eclipse JDT 论坛上提出这个
我写了下面的代码 1. function Car() { this.make = "BMW" } var x = new Car().make alert(x) 结果:显示警报 BMW 2. fu
我正在使用 wxPython 为 python 应用程序编写 UI。我已经处理了一些 OnX 函数,但我需要 OnNew 和 OnSave/SaveAs 方面的帮助 这是我的保存和另存为代码: def
每当我尝试创建一个新的 Win32 控制台应用程序或 Win32 项目时,Win32 应用程序向导弹出,项目设置项目符号点为空,并且无法单击“应用程序设置”、“完成”和“取消”按钮. 当我搜索与我类似
我创建了一个扩展点 newWizard,并在那里添加了向导(比方说 Wizard1、Wizard2、Wizard3)。我创建了一个视角,即 perspectiv1。当我创建插件项目时,所有向导标签都会
新建 >> 项目 >> Android 应用程序 项目不起作用我收到这些消息: Problem Opening Wizard The selected wizard could not be star
#include #include using namespace std; int main(void) { unsigned char* pFoo = new unsigned cha
谁能帮我理解为什么我的代码在第一段代码中的 delete[] szPassword 上失败?我知道 szPassword 只是复制“a”,而 st2 等于 8: TCHAR *szPassword =
伙计们,如果我在我的 dll 代码中覆盖全局新建和删除,这会覆盖用户代码新建和删除吗?我做了一个测试,显示用户new和delete不会受到影响。如果我想让用户代码new和delete被我的sdk ne
编译 in_ 表达式的默认 SQLAlchemy 行为对于非常大的列表来说是病态的,我想为运算符创建一个自定义的、更快的编译器。如果解决方案是一个新的运算符(即:in_list_)或者它是否覆盖了 i
new 和 delete 被称为预处理器,而 malloc 和 free 是函数。 new 和 delete 是预处理器是什么意思? 最佳答案 new 和 delete 是 C++ 运算符(如 +、(
我是一名优秀的程序员,十分优秀!