Created
September 19, 2021 12:25
-
-
Save azat/f86b0b5108748cb1943dacca0bdcd814 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Minimal exapmle of static jemalloc. | |
* | |
* $ gcc -g3 -o main main.cpp -Wl,-Bstatic -ljemalloc_pic -Wl,-Bdynamic -nodefaultlibs -lc -lpthread -ldl -lgcc | |
* (or if you have only libjemalloc.a then -ljemalloc) | |
* NOTE: order is important | |
* | |
* $ ldd main | |
* linux-vdso.so.1 (0x00007ffff7fcb000) | |
* libc.so.6 => /usr/lib/libc.so.6 (0x00007ffff7b22000) | |
* libpthread.so.0 => /usr/lib/libpthread.so.0 (0x00007ffff7b01000) | |
* libdl.so.2 => /usr/lib/libdl.so.2 (0x00007ffff7afa000) | |
* /lib64/ld-linux-x86-64.so.2 => /usr/lib64/ld-linux-x86-64.so.2 (0x00007ffff7fcd000) | |
* | |
* $ gdb -q -ex start -ex 'b malloc' -ex c -ex bt ./main | |
* | |
* Breakpoint 2, malloc (size=9) at tsd.h:341 | |
* 341 tsd.h: No such file or directory. | |
* #0 malloc (size=9) at tsd.h:341 | |
* #1 0x00007ffff7e6534f in strdup () from /usr/lib/libc.so.6 | |
* #2 0x000055555555a200 in main () at main.cpp:16 | |
* | |
* NOTE: if you configured jemalloc with prefix, | |
* than take a look at malloc hooks example [1]. | |
* | |
* [1]: http://jemalloc.net/mailman/jemalloc-discuss/2013-July/000617.html | |
*/ | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
int main() | |
{ | |
char *body = strdup("It works"); | |
puts(body); | |
free(body); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment