Compile tcmalloc on Linux

Source: Internet
Author: User

Tcmalloc (thread-caching malloc) implements the same functions as the standard glibc library's malloc, but tcmalloc is much more efficient and faster than standard malloc. Tcmalloc is one of Google-perftools tools, which is open-source and released as source code. If you think it is difficult to maintain a memory distributor, you can consider connecting the tcmalloc static library to yourProgram. The method of calling malloc in glibc is the same. All you need to do is connect the dynamic library or static library of tcmalloc to your program, and you can get an efficient, fast, and secure memory distributor. If you want to know more about tcmalloc, read here. The following describes how to compile tcmalloc in Linux and how to use it:

(1). You can go to http://code.google.com/p/google-perftools/download the source code package, you can enter the command in linux: wget http://google-perftools.googlecode.com/files/google-perftools-1.4.tar.gz to download.

(2). After the download is complete, enter the command: Tar zxvf google-perftools-1.4.tar.gz for decompression; and enter the command: CD google-perftools-1.4 to enter the source directory.

(3) enter the command:./configure to install all Google-perftools components, including four components: tcmalloc, heap-checker, heap-Profiler, and CPU-profiler. But here we only need tcmalloc, so we can enter the command :. /configure -- prefix =/usr/local -- disable-CPU-Profiler -- disable-heap-checker -- disable-debugalloc -- enable-Minimal only installs tcmalloc. -- Prefix =/usr/local indicates the installation directory. If this parameter is not specified, it is installed under/usr/local/lib/by default.

(4) enter the command: Make & make install for compilation and installation. If you want to use the minimal installation, you only need to specify a temporary directory for installation in Section (3), and then. so and. copy the file of library a to the/usr/local/lib directory, and then execute the following command to create a symbolic link: (the static library does not need a symbolic link. Only the file is copied during replication, do not copy symbolic link files)

Ln-S/usr/local/lib/libtcmalloc_minimal.so.0.0.0/usr/local/lib/libtcmalloc. So
Ln-S/usr/local/lib/libtcmalloc_minimal.so.0.0.0/usr/local/lib/libtcmalloc. so.0
Ln-S/usr/local/lib/libtcmalloc_minimal.so.0.0.0/usr/local/lib/libtcmalloc. so.0.0.0

(5). When compiling your own program, add/usr/local/lib/libtcmalloc_minimal.a at the end of the compilation option to link the static library. If a dynamic library is used, insert-L/usr/local/lib-ltcmalloc_minimal in the compilation option. After compiling your program, you can use tcmalloc. You do not need to modify either of your Code statements. If the dynamic library is used successfully, run the following command: lsof-N | grep tcmalloc. Static databases cannot be viewed.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.