1

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!

2
  • What do you do with regions that are allocated via mmap? Commented 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. Commented Feb 14, 2011 at 23:10

1 Answer 1

1

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.

http://asf.atmel.no/avr32/services/storage/mem_manager/dlmalloc/examples/example1/at32uc3a0512_evk1105/doc/html/a00036_source.html

Sign up to request clarification or add additional context in comments.

1 Comment

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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.