0

for a code main.c:

#include <stdio.h>
#include <stdlib.h>
int main()
{
    void* p = malloc(1000);
    free(p);
    return(0);
}

1st compile: gcc main.c -o a.out

2nd compile: gcc main.c -ltcmalloc -o a.out

1st use glibc stdlib,2nd use tcmalloc

and I can write main.c like this:

#include <stdio.h>
#include <google/tcmalloc.h>
int main()
{
    void* p = tc_malloc(1000);
    tc_free(p);
    return(0);
}

3rd compile: gcc main.c -ltcmalloc -o a.out

3rd is surely use tcmalloc

Is the 2nd and 3rd compile the same ?

I know tcmalloc support more functions like tc_malloc_size / tc_valloc, I guess use tc_* functions is better option to write main.c, so I have more functions ?

I can't find any man page for functions like tc_valloc / tc_new / tc_newarray / tc_valloc / tc_pvalloc

linrongbin
  • 2,967
  • 6
  • 31
  • 59

2 Answers2

0

http://sourcecodebrowser.com/google-perftools/1.4/windows_2google_2tcmalloc_8h.html

i find this man page about all tcmalloc functions

linrongbin
  • 2,967
  • 6
  • 31
  • 59
  • 1) It isn't a man page. 2) The linked document doesn't even explain what the tc_* functions do. 3) It doesn't answer the question. – Stephen C Aug 27 '15 at 02:58
0

When tcmalloc is loaded, malloc and free are aliased (see gcc documentation of __attribute alias) to tc_malloc and tc_free.

So your 2nd run and 3rd will be same.

The intention of tc_malloc and tc_free is to be able to use tcmalloc versions of malloc directly regardless of what other allocators are present.