Chinaunix首页 | 论坛 | 博客
  • 博客访问: 67932
  • 博文数量: 20
  • 博客积分: 1400
  • 博客等级: 上尉
  • 技术积分: 402
  • 用 户 组: 普通用户
  • 注册时间: 2006-10-08 17:53
文章分类

全部博文(20)

文章存档

2010年(6)

2009年(2)

2008年(8)

2006年(4)

我的朋友
最近访客

分类: C/C++

2006-11-08 02:11:23

* Always use memset along with malloc, or always use calloc.
1.永远把memset和malloc一起使用,或者永远用calloc

* Whenever writing values to pointers, make sure you cross check the number of bytes available and number of bytes being written.
2.但写数据到指针所指的内存时,一定要检查可用空间的大小,和写入的字节数。

* Before assigning the pointers, make sure no memory locations will become orphaned.
3.在给一个指针赋值的时候,确定没有内存区域丢失。

* Whenever freeing the structured element (which in turn contains the pointer to dynamically allocated memory location), first traverse to the child memory location and start freeing from there, traversing back to the parent node.
4.当释放结构体成员的内存时(这个结构体有成员指针指向动态分配的内存),要先把子内存区域释放掉,再释放父内存区域。

* Always properly handle return values of functions returning references of dynamically allocated memory.
5.适当的处理返回指向动态分配的内存的指针的函数。(好绕嘴+_+)

* Have a corresponding free to every malloc.
6.对于每一个malloc都有一个对应的free

* Make sure you are not accessing null pointer.
7.确保你不会访问null指针。

http://www-128.ibm.com/developerworks/aix/library/au-toughgame/?ca=dgr-lnxw16PointersC

阅读(1823) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~