How do realloc and memcpy work?

前端 未结 8 1021
遇见更好的自我
遇见更好的自我 2020-12-01 02:49

I have two questions.

  1. Do realloc() and memcpy() copy the entries in an array to another in a way faster than just iterating on eac

8条回答
  •  有刺的猬
    2020-12-01 03:32

    Some of the important points related to realloc(check on dev c++) : void *realloc(void *ptr, size_t size);

    1. The realloc() function shall change the size of the memory object pointed to by ptr to the size specified by size.

    2. The contents of the object shall remain unchanged up to the lesser of the new and old sizes.

    3. If the new size is larger, the contents of the newly allocated portion of the object are unspecified.

    4. If size is 0 and ptr is not a null pointer, the object pointed to is freed.

    5. If ptr is a null pointer, realloc() shall be equivalent to malloc() for the specified size.

    6. If ptr does not match a pointer returned earlier by calloc(), malloc(), or realloc() or if the space has previously been deallocated by a call to free() or realloc(), the behavior is undefined.

提交回复
热议问题