About dynamic memory allocation

About the concept of dynamic memory allocation:

https://www.cnblogs.com/yingying0907/archive/2012/07/31/2616975.html
organize their own code:
Documentation: Dynamic memory allocation .note
link: http://note.youdao.com/noteshare?id = 187f46b8a645df22430d3d88c098e852 & sub = F16D6ABF146D4D738596EE19A0697B45
summary:

  1. You do not need to pre-allocate storage space
  2. The program may be expanded or reduced space allocated
    here and can be lead-free function malloc

    prototype:

    extern void malloc(unsigned int size);
    eg: int
    p;
    p = (int )malloc(sizeof(int) 25);

There is also new and delect

can be used to generate new anonymous dynamic variables
eg: int * p = new int [10];
after use directly delete the line
eg: delete p; // release single variable
delete [] p; // release array variables

Guess you like

Origin www.cnblogs.com/fanhua666/p/11466289.html