약 realloc()
에 대해 읽는 동안 나는 무시하기보다는 명확히해야 할 몇 가지 의문점을 발견했습니다. 찾았습니다. 명료하게 정리하기 위해 번호를 붙였습니다.이 질문의 길이는 신경 쓰지 마십시오.realloc() 문제 : 이전 블록의 할당 해제, 이전 크기보다 큰 새 크기 및 정적 배열 기본 주소 전달
1)realloc()
를 사용하는 동안 그 내용으로 메모리 블록을 새 위치로 이동하는 경우, 나는 다음을 읽은?를 시킴으로 빨리 주소가 우리가()를 무료로 불리는 것처럼 이을 해제 도착하지 cplusplusreference
약 realloc
이지만 원래 메모리 블록이 이러한 경우 할당 취소된다는 제안에 가까워졌지만 귀하의 확인이 필요합니다. 여기
2)
->C90 (C++98)C99/C11 (C++11) Otherwise, if size is zero, the memory previously allocated at ptr is deallocated as if a call to free was made, and a null pointer is returned.
->If the function fails to allocate the requested block of memory, a null pointer is returned, and the memory block pointed to by argument ptr is not deallocated (it is still valid, and with its contents unchanged).
"If the new size is larger, the value of the newly allocated portion is indeterminate."
여단입니다을, 여기에 내가
을 알고 싶은 것입니다 그것으로 쓸 수 있나요 I) 새롭게 할당 된 부분?
ii) 새로 할당 된 부분을 가비지 값으로 채 웁니까?
3) 그리고 마지막으로, 배열 객체 realloc(
-)를 전달하면 형식이 여전히 char*
될 것입니다하지만, 그것은 원본 사이트에 언급, 때문에? 내가 물어 무엇 인수는 "Pointer to a memory block previously allocated with malloc, calloc or realloc.
그것은 것인가되어야한다, I는 그 내용과 메모리 블록이 새로운 위치로 이동하는 경우 realloc()
사용시 free()
"If ptr does not point to a block of memory allocated with the above functions, it causes undefined behavior."
나는'cplusplusreference'를 사용하지 말라는 권고를 받았다. 그러나 한 달후 그 사이트에서 메모를하고있는 동안 충고가 최근에 있었다. 전환하는 데 시간이 걸릴 것이다 !! 그리고 글쎄, 그렇지 않다. ** 나쁜 :-) !! – Jugni