[ACCEPTED]-Where do malloc() and free() store allocated sizes and addresses?-free

Accepted answer
Score: 15

There are lots of ways in which malloc/free 11 can store the size of the memory area. For 10 example, it might be stored just before 9 the area returned by malloc. Or it might 8 be stored in a lookup table elsewhere. Or 7 it might be stored implicitly: some areas 6 might be reserved for specific sizes of 5 allocations.

To find out how the C library 4 in Linux (glibc) does this, get the source 3 code from http://ftp.gnu.org/gnu/glibc/ and look at the malloc/malloc.c file. There 2 is some documentation at the top, and it 1 refers to A Memory Allocator by Doug Lea.

Score: 1

This is up to the implementation of the 5 standard library, of course. So your best 4 bet would probably be to dig through the 3 source of the library (glibc is the default on 2 Linux) and see if you can figure it out. It 1 is probably not going to be trivial.

More Related questions