How does malloc work in a multithreaded environment?

glibc 2.15 operates multiple allocation arenas. Each arena has its own lock. When a thread needs to allocate memory, malloc() picks an arena, locks it, and allocates memory from it. The mechanism for choosing an arena is somewhat elaborate and is aimed at reducing lock contention: /* arena_get() acquires an arena and locks the corresponding … Read more

What’s the meaning of the %m formatting specifier?

m conversion specifier is not C but is a GNU extension to printf: From GNU documentation: http://www.gnu.org/software/libc/manual/html_node/Other-Output-Conversions.html The ‘%m’ conversion prints the string corresponding to the error code in errno. See Error Messages. Thus: fprintf (stderr, “can’t open `%s’: %m\n”, filename); is equivalent to: fprintf (stderr, “can’t open `%s’: %s\n”, filename, strerror (errno)); The ‘%m’ … Read more

What does ‘corrupted double-linked list’ mean

I have found the answer to my question myself:) So what I didn’t understand was how the glibc could differentiate between a Segfault and a corrupted double-linked list, because according to my understanding, from perspective of glibc they should look like the same thing. Because if I implement a double-linked list inside my program, how … Read more

Will malloc implementations return free-ed memory back to the system?

The following analysis applies only to glibc (based on the ptmalloc2 algorithm). There are certain options that seem helpful to return the freed memory back to the system: mallopt() (defined in malloc.h) does provide an option to set the trim threshold value using one of the parameter option M_TRIM_THRESHOLD, this indicates the minimum amount of … Read more

What is GLIBC? What is it used for?

Its the implementation of Standard C library described in C standards plus some extra useful stuffs which are not strictly standard but used frequently. Its main contents are : 1) C library described in ANSI,c99,c11 standards. It includes macros, symbols, function implementations etc.(printf(),malloc() etc) 2) POSIX standard library. The “userland” glue of system calls. (open(),read() … Read more

How to upgrade glibc on Debian?

I was able to install libc6 2.17 in Debian Wheezy by editing the recommendations in perror’s answer: IMPORTANT You need to exit out of your display manager by pressing CTRL–ALT–F1. Then you can stop x (slim) with sudo /etc/init.d/slim stop (replace slim with mdm or lightdm or whatever) Add the following line to the file … Read more

Check glibc version for a particular gcc compiler

even easier use ldd –version This should return the glibc version being used i.e. $ ldd –version ldd (GNU libc) 2.17 Copyright (C) 2012 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO … which is the same result as running my libc library $ /lib/libc.so.6 GNU … Read more

Why is this code using strlen heavily 6.5x slower with GCC optimizations enabled?

Testing your code on Godbolt’s Compiler Explorer provides this explanation: at -O0 or without optimisations, the generated code calls the C library function strlen; at -O1 the generated code uses a simple inline expansion using a rep scasb instruction; at -O2 and above, the generated code uses a more elaborate inline expansion. Benchmarking your code … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)