I am doing some hacking with Doug Lea's malloc.c (under Linux x86_64), and I need to find the lowest allocated address and the address of the high end of the highest allocated chunk--in other words, the bounds of allocated memory--which of course excludes the mspace's struct malloc_state bookkeeping structure. How can I get these addresses? Note that I am not looking for the bounds of the entire heap, but only those of the allocated portion, which will usually include unallocated "holes" between the lowest and highest allocated chunks. I have been using the least_addr and top fields of the malloc_state structure. Is this correct? Thank you!
- What do you do with regions that are allocated via mmap?user611775– user6117752011-02-14 22:24:52 +00:00Commented Feb 14, 2011 at 22:24
- In my case, I am not worried about those, because I am mmap-ing a large swath of memory at initialization and then using Doug Lea's create_mspace_with_base with mspace_track_large_chunks, and then mspace_malloc for each call to malloc.Amittai Aviram– Amittai Aviram2011-02-14 23:10:57 +00:00Commented Feb 14, 2011 at 23:10
Add a comment |
1 Answer
From what I understand, this should work. Malloc uses these values to define where it can allocate memory.
Here is a malloc implementation, it may help answer your questions.
1 Comment
Amittai Aviram
Thanks! I already have Doug Lea's malloc.c, which is what that link goes to. BTW, any idea why least_addr would have a value lower than the address of the mspace itself? I was expecting that the malloc_state structure would take up the first sizeof(struct malloc_state) bytes of the mspace, so least_addr should come right after that, but my testing shows a least_addr value lower than the pointer address of the mspace.