malloc: 对象 0x10003b3c4 的 *** 错误:未分配正在释放的指针 *** 在malloc_error
malloc: *** error for object 0x10003b3c4: pointer being freed was not allocated *** set a breakpoint in malloc_error_break to debug
我是编程C++新手,请耐心等待:)我的问题是模型(DGVM(运行到最后,但我收到的最后一条消息是"malloc:* 对象 0x10003b3c4 的错误:未分配正在释放的指针* 在malloc_error_break中设置断点以进行调试"。调试器指出这一点:
clTreePop::~clTreePop() {free(Trees);}
调试器指向free(Trees)
并给出消息:"EXC_BAD_INSTRUCTION(代码=EXC_i386_INVOP,子代码=0x0("。我做错了什么?谢谢。
代码中可能对此问题很重要的部分:
void clTreePop::addFirstTree( double init_mass)
{
clTree Tree( init_mass, -1. , pop_size_, count_trees_);
Trees = (clTree *) malloc(sizeof(clTree));
Trees[0] = Tree;
pop_size_ ++;
new_born_ ++;
count_trees_ ++;
root_biomass_ += Tree.getBr();
stem_biomass_ += Tree.getBS();
leaf_biomass_ += Tree.getBl();
canopy_area_ += Tree.getCanopyArea();
gc_weighted_ += Tree.getGc();
max_height_ += MyMax(max_height_,Tree.getHeight());
basal_area_ += Tree.getStemArea();
return; }
首先C++ 您不需要使用 malloc,因为分配可以通过不同的、更好的方式完成,如果没有,至少更简单。Malloc 是一种旧的、低级的 C(不是C++(方式。尝试使用
clTree *Trees = new clTree;
您复制的代码没有完全显示情况,尽管我可以看到的是
Trees = (clTree *) malloc(sizeof(clTree));
您应该使用:
clTree *Trees = (clTree *) malloc(sizeof(clTree));
这样,您可以创建一个指针,然后您向其附加您分配的结构。
错误"EXC_BAD_INSTRUCTION(代码=EXC_i386_INVOP,子代码=0x0("表示您的代码与计算机体系结构(处理器、系统等(之间存在某种不兼容性。我不知道这件事,但我认为这是由我之前列出的错误引起的。
相关文章:
- 如果没有malloc,链表实现将失败
- 释放错误后堆使用
- G锁定铸造到基础上会释放模拟行为
- C++:在被本地字符串捕获后释放或销毁 malloc'd char *?
- 错误:malloc:对象 0x7f9edf504080 的 *** 错误:未分配正在释放的指针
- 如何修复对象在释放后可能修改的malloc错误
- std::unordered_map 如何释放使用 malloc 创建的结构.是否需要对地图进行 2 次查询
- malloc: 对象 0x00 的 *** 错误:未分配正在释放的指针
- malloc: 对象 0x10003b3c4 的 *** 错误:未分配正在释放的指针 *** 在malloc_error
- 如何在功能之外释放 malloc
- 带有QT的C 应用中的IIMEBRA代码给出malloc:***对象XXXXXX的错误:未分配释放的指针
- 如果通过委托给“malloc”的重载“new[]”分配,“释放”内存是否安全
- malloc: 对象 0x7fff5fbff350 的 *** 错误:未分配正在释放的指针
- malloc: 对象 0x1029249b0 的 *** 错误:未分配正在释放的指针
- 释放包含恶意字符串的 malloc'd 结构
- 在循环中释放malloc后的内存
- c++错误:如何解决对象的malloc: ***错误.未分配被释放的指针
- 未分配被释放的Malloc指针
- 在许多malloc/释放小块内存后,未能malloc大块内存
- 被释放的指针没有在构造函数中分配 realloc 和 malloc