- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我正在从 com 端口读取数据。因为不知道什么时候有数据,所以一直在一个线程里读。
当我读取了足够多的字节后,我通过发布一 strip 有指向字符串指针的消息让主线程知道这一点:
msg[i] = '\0';
completeMsg = new char[i];
strcpy(completeMsg, msg);
PostMessage(hDlg, BT_MSG, NULL, (LPARAM) completeMsg);
i = 0;
主线程对此消息的响应是:
case BT_MSG:
{
char* msg = (char*) lParam;
ShowMsg(msg);
delete [] msg;
break;
}
但似乎不允许在此线程中删除,因为我在执行删除行时收到此错误:
Windows has triggered a breakpoint in SPO.exe.
This may be due to a corruption of the heap, which indicates a bug in SPO.exe or any of the DLLs it has loaded.
This may also be due to the user pressing F12 while SPO.exe has focus.
The output window may have more diagnostic information.
我应该使用一些全局变量还是发回消息让读取线程处理删除?它没有消息循环自动取款机,所以我不想为此添加一个。
最佳答案
您应该能够在一个线程中使用 new
并在另一个线程中使用 delete
,前提是您链接到编译器的多线程运行时库。
但是,看起来您实际上遇到了缓冲区溢出。您使用 msg[i]=0
以 null 终止 msg
,但只分配 i
字节 --- 您可能需要 new字符[i+1]
.
关于c++ - 在一个线程中新建并在另一个线程中删除,不允许吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5608199/
我目前正在开发自己的内存泄漏跟踪系统。 我正在使用 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++ 运算符(如 +、(
我是一名优秀的程序员,十分优秀!