- 论坛徽章:
- 1
|
我弄了一个Huffman编码程序,执行程序后总是出现错误信息munmap_chunk(): invalid pointer。查了资料知道动态分配的指针被修改以后会导致munmap_chunk() 我把可能出错的代码贴出来让大家帮忙改一下
HuffmanTree::HuffmanTree(const HuffmanTree &h){}
HuffmanTree::HuffmanTree(void)
{
root = new HuffmanNode[MAX_VALUE*2-1];
}
HuffmanTree::~HuffmanTree(void){delete []root;}】
这个好像没什么错误,还有
buffer = new char [(int)length];
in.read (buffer,length);
in.close();
for(i=0; i<length; ++i)
{
tmp = (unsigned char)buffer[i];
weight[tmp]++;
}
//initialize the weight of each leaf node
for (int i = 0; i < MAX_VALUE; ++i)
root[i].weight = weight[i];
root[MAX_VALUE*2-1].weight = INT_MAX;
root[MAX_VALUE*2-2].index = -1;
delete[] buffer;
return 0;
} |
|