* 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
阅读(1860) | 评论(0) | 转发(1) |