malloc관련 문서나 커널 문서에 가면 많이 보이는 이 함수들은 기능이 결과적으로 보면 비슷하다. 다 if문을 좀 더 효율적으로 동작시키기 위한 장치이다. 기본적으로 __builtin_expect는 __builtin_expect(조건식, 예상되는 값)이렇게 사용하는데 보통 if문의 조건식에 저 __builtin_expect함수를 넣어준다. 이 함수의 장점은 단순 if문보다 실행속도가 빨라진다는 것이다. https://stackoverflow.com/questions/7346929/what-is-the-advantage-of-gccs-builtin-expect-in-if-else-statements What is the advantage of GCC's __builtin_expect in if else ..
mstate av; mchunkptr oldtop, p; INTERNAL_SIZE_T bytes, sz, csz, oldtopsize; void *mem; unsigned long clearsize; unsigned long nclears; INTERNAL_SIZE_T *d; 사용될 변수들을 선언해놓는다. /* size_t is unsigned so the behavior on overflow is defined. */ bytes = n * elem_size; #define HALF_INTERNAL_SIZE_T \ (((INTERNAL_SIZE_T) 1) = HALF_INTERNAL_SIZE_T, 0)) { if (elem_size != 0 && bytes / elem_size != n) { __set_..
/* We overlay this structure on the user-data portion of a chunk when the chunk is stored in the per-thread cache. */ typedef struct tcache_entry { struct tcache_entry *next; } tcache_entry; tcache_entry 구조체의 모습이다. next라는 이름의 포인터밖에 없다. /* There is one of these for each thread, which contains the per-thread cache (hence "tcache_perthread_struct"). Keeping overall size low is mildly important. Not..
unlink 대상 청크의 크기와 다음 청크의 prev_size 대조 대상 청크의 fd (이 청크 직전에 free된 청크)의 bk가 대상 청크와 같은지 확인 대상 청크의 bk (이 청크 직후에 free된 처크)의 fd가 대상 청크와 같은지 확인 smallbin 범위(32비트일경우 512바이트미만 64비트일경우 1024바이트미만)가 아닐때(즉 largebin에 들어갈 크기 일때) && 대상 청크의 fd_nextsize가 null이 아닐때 fd_nextsize(대상 청크 직전에 free된청크)의 bk_nextsize가 대상청크인지 확인 bk_nextsize(대상 청크 직후에 free된 청크)의 fd_nextsize가 대상청크인지 확인 large bin 은 fd_nextsize와 bk_nextsize를 통해 c..