google ai 답변 코드
| $ cat mallinfo.c #include <malloc.h> #include <stdio.h> #include <stdlib.h> int main(void) { void *ptr = malloc(1024 * 1024); struct mallinfo2 info = mallinfo2(); printf("할당된 메모리(uordblks): %zu bytes\n", info.uordblks); printf("가용 메모리(fordblks): %zu bytes\n", info.fordblks); printf("mmap 크기(hblkhd): %zu bytes\n", info.hblkhd); free(ptr); return 0; } |
malloc 되느건 mmap을 통해서니까..
1024 * 1024 = 1048576 + 4096 = 1052672
얼추 맞는건가? 그런데
| $ ./a.out 할당된 메모리(uordblks): 656 bytes 가용 메모리(fordblks): 134512 bytes mmap 크기(hblkhd): 1052672 bytes |
+
음.. 왜 할당된 메모리가 656 인진 감이 안오네?
| sizeof(struct mallinfo2) 80 bytes |
[링크 : https://www.gnu.org/software/gnulib/manual/html_node/mallinfo2.html]
[링크 : https://man7.org/linux/man-pages/man3/mallinfo2.3.html]
[링크 : https://codebrowser.dev/glibc/glibc/malloc/tst-mallinfo2.c.html]
'Linux API > linux' 카테고리의 다른 글
| MALLOC_ARENA_MAX (0) | 2026.10.26 |
|---|---|
| openpty, forkpty, login_tty (0) | 2026.09.09 |
| kernel driver (0) | 2026.04.06 |
| 커널 cmdline 관련 함수 (0) | 2026.04.03 |
| kernel input_event() (1) | 2025.12.23 |
