From 9152b6341f2fb0bb69dbdd8edd2f69a5d1d02460 Mon Sep 17 00:00:00 2001 From: Jason Evans Date: Tue, 29 Oct 2013 17:57:40 -0700 Subject: [PATCH] Updated Getting Started (markdown) --- Getting-Started.md | 64 +++++++++++++++++++++++++++------------------- 1 file changed, 38 insertions(+), 26 deletions(-) diff --git a/Getting-Started.md b/Getting-Started.md index 5d3d1f9..1e864b2 100644 --- a/Getting-Started.md +++ b/Getting-Started.md @@ -1,55 +1,67 @@ All of the following examples assume a standard developer environment on Unix-like machine, and something like the following variables in the environment: - export JEMALLOC_PATH=$HOME/local +```sh +export JEMALLOC_PATH=$HOME/local +``` There are several ways to integrate jemalloc into an application. Here are some examples, from simplest to most involved: * Use the LD_PRELOAD environment variable to inject jemalloc into the application at run time. Note that this will only work if your application does _not_ statically link a malloc implementation. - LD_PRELOAD=${JEMALLOC_PATH}/lib/libjemalloc.so.1 app + ```sh + LD_PRELOAD=${JEMALLOC_PATH}/lib/libjemalloc.so.1 app + ``` * Link jemalloc into the application at build time, but use it as a generic malloc implementation: - cc app.c -o app -L${JEMALLOC_PATH}/lib -Wl,-rpath,${JEMALLOC_PATH}/lib -ljemalloc + ```sh + cc app.c -o app -L${JEMALLOC_PATH}/lib -Wl,-rpath,${JEMALLOC_PATH}/lib -ljemalloc + ``` * Compile jemalloc with an API prefix (see the `--with-jemalloc-prefix` configure option), link with jemalloc at build time as above, but use jemalloc distinctly from the system allocator. Once you have jemalloc integrated into your application, you can use special features in a variety of ways: -* Set the `/etc/malloc.conf` symlink or `MALLOC_CONF` environment variable to tune jemalloc, e.g. +* Set the `/etc/malloc.conf` symlink or [`MALLOC_CONF`](http://www.canonware.com/download/jemalloc/jemalloc-latest/doc/jemalloc.html#tuning) environment variable to tune jemalloc, e.g. - export MALLOC_CONF="prof:true,lg_prof_sample:1,prof_accum:false,prof_prefix:jeprof.out" + ```sh + export MALLOC_CONF="prof:true,lg_prof_sample:1,prof_accum:false,prof_prefix:jeprof.out" + ``` * Directly invoke jemalloc features in the application: - Compile the following code as such: - gcc ex_stats_print.c -o ex_stats_print -I${JEMALLOC_PATH}/include -L${JEMALLOC_PATH}/lib \ - -Wl,-rpath,${JEMALLOC_PATH}/lib -ljemalloc + ```sh + gcc ex_stats_print.c -o ex_stats_print -I${JEMALLOC_PATH}/include -L${JEMALLOC_PATH}/lib \ + -Wl,-rpath,${JEMALLOC_PATH}/lib -ljemalloc + ``` - ex_stats_print.c: - #include - #include + ```c +#include +#include - void - do_something(size_t i) - { +void +do_something(size_t i) +{ - // Leak some memory. - malloc(i * 100); - } + // Leak some memory. + malloc(i * 100); +} - int - main(int argc, char **argv) - { - size_t i; +int +main(int argc, char **argv) +{ + size_t i; - for (i = 0; i < 1000; i++) { - do_something(i); - } + for (i = 0; i < 1000; i++) { + do_something(i); + } - // Dump allocator statistics to stderr. - malloc_stats_print(NULL, NULL, NULL); + // Dump allocator statistics to stderr. + malloc_stats_print(NULL, NULL, NULL); - return (0); - } \ No newline at end of file + return (0); +} + ``` \ No newline at end of file