Realloc () function

Source: Internet
Author: User

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 );

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.