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.)
-
Have you read the wikipedia article on memory allocation and its section on dlmalloc?– gfourJul 10, 2012 at 15:12
1 Answer
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.
-
1Great answer, wondering if you could clarify something - is dlmalloc used as the malloc on Android, maintaining separate pools in each process for ordinary usage and for dalvik, or does dalvik use dlmalloc while other malloc calls (in a jni lib or whatever) end up using something else? May 21, 2013 at 22:48