메모리 동적할당
조회수 572회
free라는 function으로 memory alloc한걸 dealloc 해주잖아요.
근데 인자로는 단순히 포인터 하나만 받게 되는데, 얼마만큼 동적할당이 되어있는지, 크기를 넘겨주지도 않았고, 따라서 얼마만큼 동적할당을 해제시켜줄지는 어떻게 아는거예요 ?
-
(•́ ✖ •̀)
알 수 없는 사용자
1 답변
-
https://stackoverflow.com/a/1957125/9437175
위 링크를 참고 하시면 되구요, 메모리를 할당할 때 여분의 메모리를 조금 더 할당해서 해당 메모리에 관한 추가 정보를 저장하기 때문에 크기를 알 수 있습니다.
When memory is allocated, additional information is stored as part of a data structure maintained by the heap manager. This information includes, among other things, the block’s size, and is typically placed immediately adjacent to the allocated block.
-
(•́ ✖ •̀)
알 수 없는 사용자
-
댓글 입력