2013-08-14 6 views

답변

2

첫 번째 매개 변수는 콜백 함수 포인터이고 두 번째 매개 변수는 콜백에 데이터를 전달하기위한 것입니다. 이 매개 변수를 사용하여 파일에 쓰기를 구현할 수 있습니다.

malloc_stats_print 보이드 (공극 (* write_cb) (공극 * CONST 숯 *) 무효 * cbopaque, CONST 숯불 * OPTS) 다음 jemalloc manual page 가입일

0
/*Actually The default function, it uses inside print the stat data on STDERR output stream. To print it to a file, It needs to provide a callback function, which it will call to print the buf stream into. */ 

int g_fd; 

void print_my_jemalloc_data(void *opaque, const char *buf); 

int main() 

{ 

    int fd = open("heap_stats.out,O_CREAT|O_WRONLY,0666); 

    g_fd = fd; 

    malloc_stats_print(print_my_jemalloc_data,NULL,NULL); 

    /*Passing my callback routine which jemalloc will use internally to print data into*/ 

return 0; 

} 

void print_my_jemalloc_data(void *opaque,const char *buf) 
{ 
write(g_fd,buf,strlen(buf));`enter code here` 
} 

당신은 동일한 서명으로, 당신의 기능을 대체하고, malloc_stat_print API로 대체 할 수있다, 기능을 다시 첫 번째 매개 변수를 호출합니다. 이 파일은 buf로 전달 될 것입니다.이 파일은 전에 열어 둔 정의 된 파일 스트림으로 인쇄 할 수 있습니다 ..

관련 문제