I'm using OS X 10.10.5 now, and I'm doing an experiment about malloc and heap like below:
#include <stdio.h>
#include <stdlib.h>
int main() {
int *p;
p = malloc(sizeof(int));
*p = 100;
printf("the malloc p pointer addr is %x\n", p);
getchar();
}
the out put is the malloc p pointer addr is c3404ba0
;
I think address 0xc3404ba0
is allocated by maclloc as part of the process heap.
Then I use the vmmap
tool to get the memory map, the result is:
We can see that the 0xc3404ba0
is not in the heap area, but it's realy the pointer to the allocated memory. What's wrong with that?
It fix now, when I use %p instead of %x, the output is the malloc p pointer addr is 0x7fe131404ba0
and the vmmap output is:
thanks to @Alex Lop.