1. It is used to change the configured memory space in the heap. The function declaration is as follows:
Extern void * realloc (void * _ PTR, size_t _ size); the first parameter is the location of the original heap space to be changed, and the size is the new memory size.
2. Reduce memory: realloc () only modifies the index information, but does not mean that the reduced part can be accessed. The reduced part of memory will be handed over to the operating system for management.
3. increase memory size: (1) if the current memory segment has the required memory space, the memory space will be extended directly, and realloc () will return the original pointer. (2) If the idle bytes behind the current memory segment are insufficient, use the first memory block in the heap to meet this requirement and copy the current data to a new location, release the original data block and return the location of the new memory block. (3) If the application fails, null is returned, and the pointer is still valid. To prevent the original pointer from being valid, do not use the following statement: PTR = realloc (PTR, new_amount );