malloc_stats 에 대한 궁금...

noohgnas의 이미지

아래 cinsk 님의 malloc() 추적에 대한 글을 보고 공부중입니다.

malloc.h 에 malloc_stats()라는 함수가 있다는 것을 알았습니다. 감사합니다. :D

제가 작성한 아래 코드를 실행하면,

#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>

int main(void)
{
    char *tmp = "noohgnas";
    char *target;

    malloc_stats();
    target = (char*)malloc(sizeof(char)*strlen(tmp)+1);

    malloc_stats();

    strcpy(target,tmp);

    free(target);

    malloc_stats();

    return 0;
}

Arena 0:
system bytes     =       2288
in use bytes     =         32
Total (incl. mmap):
system bytes     =       2288
in use bytes     =         32
max mmap regions =          0
max mmap bytes   =          0
Arena 0:
system bytes     =       2288
in use bytes     =         48
Total (incl. mmap):
system bytes     =       2288
in use bytes     =         48
max mmap regions =          0
max mmap bytes   =          0
Arena 0:
system bytes     =       2288
in use bytes     =         32
Total (incl. mmap):
system bytes     =       2288
in use bytes     =         32
max mmap regions =          0
max mmap bytes   =          0

와 같이 나타납니다. free() 하면 in use bytes가 malloc() 하기 전의 크기로 돌아옵니다만.. 여기서 32 라는 숫자가 궁금합니다. 물론, 넘겨집으면 그냥 OS가 필요한 쓰는거겠지.. 라고 생각할 수도 있습니다만 내부 속사정을 알고싶습니다. :D

감사합니다.

cinsk의 이미지