Memory Management Checklist

Source: Internet
Author: User

(1) The variables on the stack must be initialized.

(2) memory allocated from the stack must be initialized.

(3) whether the local variables on the stack have large array variables, leading to stack overflow exceeding the default limit

(4) Whether unreasonable recursion exists in the stack, leading to stack overflow beyond the default limit

(5) It is necessary to handle the situation of memory depletion. Pay attention to the new processing method when the memory is insufficient.

(6) After a pointer is released, the pointer variable must be assigned null to avoid the appearance of a wild pointer.

(7) do not delete or free the same pointer twice or more.

(8) to operate the array, make sure that the subscript does not cross the border.

(9) Avoid frequent requests for and release of small memory with unequal length

(10) memory application and release must be paired to prevent memory leakage

(11) The Destructor array type must be in the [] Delete format.

(12) free, malloc, delete, and new must be paired and cannot be mixed.

(13) The use of threads also occupies the memory and determines whether the thread is released.

(14) for operator new and operator Delete functions that overwrite the standard, they must be paired and overwritten.

(15) For memory length, you cannot calculate it by yourself. You must use sizeof and note byte alignment.

(16) whether to consider the '/0' terminator at the end of the string for the C string, for example, char * P = "wokao"; char buffer [5]; strpcy (buffer, p );

(17) Use strcpy (char * DEST, const char * SRC) and other STR series functions to check whether the Dest buffer overflow is taken into account. the Dest Buffer Overflow should be prioritized to ensure that the Dest does not overflow or the N family function is used.

(18) Use int sprintf (char * string, char * farmat [, argument,...]); whether overflow is taken into account during function execution. Therefore, ensure that string does not overflow or use the snprintf function.

(19) replace gets with the fgets Function

(20) ensure that the operation space does not overflow when the mem family functions are used.

(21) Replace the cyclic operation with the mem function family whenever possible during memory copy, assignment, or initialization.

(22) Be careful about the differences between pointers and arrays, such as const char * P = "12345678", char buffer [] = "12345678"; cout <sizeof (p) <Endl, cout <sizeof (buffer) <Endl; and so on

(23) Whether to modify a constant string, such as const char * P = "wokao", P [0] = 'R ';

(24) whether to consider whether the array name is passed as a function parameter, the array degrades to a pointer.

(25) Avoid the rapid consumption of memory due to the generation of a large number of temporary objects, such as consecutive long string + operations.

(26) Avoid referencing temporary objects, such as string a = "123"; string B = "456"; const char * P = (a + B ). c_str ();

(27) when passing function parameters, try to use pointers or references to avoid directly passing values, especially for large object types.

(28) whether the use of the auto_ptr smart pointer takes into account ownership transfer, resulting in memory release

(29) Does the Vector class automatically expand the memory by 2x when its internal memory is insufficient? Does it affect the program running?

(30) when using the STL string class, whether to consider the impact of the diversity of the string class implementation on the program.

(31) whether the corresponding memory resources are released when an object needs to end its lifecycle in a module. For example, whether the corresponding memory resources are deleted in the C ++ destructor

(32) Be careful when the shared memory stores vtable objects. When another process is deleted, illegal access is allowed.

(33) failed to perform memset Initialization on objects containing vtable

(34) offsetof must be used to calculate the Structure Variable Offset

 

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.