linux jemalloc memory allocator installation and use

1. Installation

Download link: https://github.com/jemalloc/jemalloc/releases

The latest version is jemalloc-5.2.0

Unzip the file after downloading:

The installation officially starts below~

step 1:

./autogen.sh

step 2:

make

step 3:

sudo make install

If there is no super authority in this step, the following problems will occur:

The installation is complete in three simple steps

After the installation is complete, you will see the relevant content of jemalloc in the lib, include, and bin directories under /usr/local.

(1)/usr/local/lib

(2)/usr/local/include

(3)/usr/local/bin

2. Problems that may be encountered during installation

1、install: cannot stat ‘doc/jemalloc.html’: No such file or directory

solution:

Use the following statement when make install:

make install_bin install_include install_lib

 Source: https://github.com/jemalloc/jemalloc/issues/231

Three, use

Write the test program jemalloc.c:

#include <stdio.h>
#include <jemalloc/jemalloc.h>
  
void jemalloc_test(int i)
{
        malloc(i*100);
}
 
int main(int argc, char **argv)
{
        int i;
        for(i=0;i<1000;i++)
        {
                jemalloc_test(i);
        }
        malloc_stats_print(NULL,NULL,NULL);
        return 0;
}

For compilation, first test step by step, using the following compilation methods, the first two failed.

Compilation method 1:

gcc jemalloc.c -o jemalloc

Compilation failed.

Compilation method 2:

gcc jemalloc.c -o jemalloc -ljemalloc

Compilation is successful, run the test:

Failed to run

Compilation method 3:

First switch to super user permissions:

sudo bash

Add the jmalloc library into the system: 

echo /usr/local/lib >> /etc/ld.so.conf
ldconfig

 Compile:

gcc jemalloc.c -o jemalloc -ljemalloc

 run:

It can be seen from the above figure that the operation was successful~

 

 

Guess you like

Origin blog.csdn.net/whatday/article/details/115203034