Learn note(cpp): take care when use new in a code block.
来源:互联网 发布:域名报毒查询 编辑:程序博客网 时间:2024/06/12 04:18
When I want to write a program to store the hash code of a file into a hash table, I find that whenever I expend the table and call the delete in the second time, an error: “double free” will occur. HashNode* ht = new HashNode[len];
while(....){
if (overload(size)){
delete [] ht;
len = update(len);
HashNode* ht = new HashNode[len];
....
}
....
}
Just at the moment I call the delete at the second time, the error occurred.
Actually, it was my fault.
I’ve ignored the type* var = new type;
is the same as type* var;var = new type;
Yeah, this means I have to declare first, and then distribute the memory.
so the
HashNode* ht = new HashNode[len];
is not safe to use, because the ht I declared in “if ” will be released exactly after this block. Of cause the double free will occur.
- Learn note(cpp): take care when use new in a code block.
- Take a note
- learn-to-use-the-new-router-in-expressjs-4
- Take care of fopen
- take care of myself
- TAKE CARE OF PERMISSIONS!
- When to use static method in a java class
- READING NOTE: A New Convolutional Network-in-Network Structure
- Learn a New Language
- Use View.isInEditMode() in your custom views to skip code when shown in Eclipse
- Use View.isInEditMode() in your custom views to skip code when shown in Eclipse
- Tip: Use View.isInEditMode() in your custom views to skip code when shown in Eclipse
- Tip: Use View.isInEditMode() in your custom views to skip code when shown in Eclipse
- Tip: Use View.isInEditMode() in your custom views to skip code when shown in Eclipse
- Tip: Use View.isInEditMode() in your custom views to skip code when shown in Eclipse
- Tip: Use View.isInEditMode() in your custom views to skip code when shown in Eclipse
- Webdriver take screen shot when case failed use TestNG
- Webdriver take screen shot when case failed use TestNG
- leetcode:Invert Binary Tree
- Object的方法
- iOS开发可变参数va_list、va_start、va_end
- 条件随机场入门
- PE总结14---PE文件结构之重定位表 (IMAGE_BASE_RELOCATION)
- Learn note(cpp): take care when use new in a code block.
- hdu4263 Red/Blue Spanning Tree
- 安卓内部存储(三)SQLite数据库
- 1.why MR?
- 调用天气预报代码
- LeetCode 206:Reverse Linked List
- 将布局文件设置到对话框里面
- nginx 的安装
- python日期操作