Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between malloc and dlmalloc

For allocating a memory region in dalvik heap, applications use dlmalloc, instead of normal malloc, Why dlmalloc is used, and how it differs from malloc. (As per I know, for allocating dalvik heap while creating dalvik VM, malloc is used.)

like image 984
LKL Avatar asked Jul 09 '12 01:07

LKL


1 Answers

The high-order bit was that Dalvik needed to have an underlying allocator that was separate from the default malloc-managed heap, so it could have the right kind of control over how allocation happened, knowing that other subsystems wouldn't be interfering.

As it turned out, dlmalloc was a reasonably-mature existing library that provided the isolation and the hooks we needed. The intent (up to the point when I left the team) was that eventually we'd replace it with something more bespoke, but it never became a sufficiently pressing issue to take that particular plunge.

As for detailed differences between dlmalloc and malloc: dlmalloc is a specific implementation of the traditional libc malloc API, whereas "malloc" per se isn't specific to a particular implementation. But even if you got specific, I doubt I could suggest anything more than "read the code" anyway.

like image 57
danfuzz Avatar answered Oct 22 '22 22:10

danfuzz