动态指针数组,释放内存问题(Dynamic pointer array, freeing memory problems).docVIP

  • 11
  • 0
  • 约1.05万字
  • 约 17页
  • 2017-09-07 发布于河南
  • 举报

动态指针数组,释放内存问题(Dynamic pointer array, freeing memory problems).doc

动态指针数组,释放内存问题(Dynamic pointer array, freeing memory problems)

动态指针数组,释放内存问题(Dynamic pointer array, freeing memory problems) C language memory allocation and release (construction of multidimensional dynamic arrays) (2012-02-29 00:17) Tags: C language memory dynamic classification: C/C++ A static and dynamic array array. Static array is more common, the length of the array of predefined, throughout the program, once a given size cannot be changed after the length of static memory array themselves responsible for the release of occupation. Dynamic array length can be with the program needs to specify the size. The array of dynamic memory allocation function (malloc) from the stack (heap) on the allocation of storage space, only when the program execution allocation function, to allocate memory for it at the same time, the programmer is responsible for releasing the allocated memory (free). Two. Why do you want to use a dynamic array? In practice, often this happens, the required memory space depends on the actual input data, and cannot be determined in advance. For this problem, it is difficult to solve by static array method. In order to solve the above problems, the C language provides some memory management functions, these memory management functions with the pointer can be dynamically allocated memory space, to build a dynamic array, but also the space for recovery is no longer in use, provides a means for the effective use of memory resources. Three. Compared with the static dynamic array array For static array, its creation is very convenient, there is no need to use after the release, but also create references to the simple, unable to change its size is its fatal weakness! For a dynamic array, it creates trouble, after use must be released by the programmers themselves, otherwise will cause serious memory leaks. But its use is very flexible, according to the procedures need to be dynamically allocated size. Four. How to build a dynamic array? Construction of dynamic array, we follow the following principles: When the ap

您可能关注的文档

文档评论(0)

1亿VIP精品文档

相关文档