[C + +] Realloc Memory

Source: Internet
Author: User

function Description
void* realloc (void* ptr, size_t size);
GrammarPointer name = (data type *) realloc (to change the memory size of the pointer name, the new size). The new size can be large and small (but note that if the new size is smaller than the original memory size, it may result in data loss, use caution!) )header File#include <stdlib.h> some compilers require # include <malloc.h>, alloc.h header files can be used in TC2.0functionFirst determine whether the current pointer has enough contiguous space, if there is, expand the address pointed to by Mem_address, and return mem_address, if the space is not enough, first in accordance with the size specified by newsize to allocate space, the original data from beginning to end copied to the newly allocated memory area, Then release the original mem_address memory area (Note: The original pointer is automatically freed, do not need to use free), and return the new allocated memory area of the first address. That is, the address of the memory block is redistributed.return valueReturns a pointer to the allocated memory if the reallocation succeeds, otherwise null pointer is returned.NoteUse the free () function to release memory blocks when memory is no longer in use.

[C + +] Realloc Memory

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.