ubuntu64:~$ strace ./test_mem
execve("./test_mem", ["./test_mem"], [/* 32 vars */]) = 0
. . .
brk(0xd0e000) = 0xd0e000 //通过将堆顶向高地址移动到0xd0e000为进程分配内存
write(1, "before malloc, the top of heap i"..., 43before malloc, the top of heap is 0xced000) = 43
write(1, "address of a is 0xced420 top of "..., 62address of a is 0xced420 top of heap after malloc is 0xd0e000) = 62
brk(0xd40000) = 0xd40000 // 同样通过移动堆顶分配内存
write(1, "address of a is 0xd06430 top of "..., 62address of a is 0xd06430 top of heap after malloc is 0xd40000) = 62
write(1, "address of a is 0xd1f440 top of "..., 62address of a is 0xd1f440 top of heap after malloc is 0xd40000) = 62
brk(0xd72000) = 0xd72000 // 同样通过移动堆顶分配内存
write(1, "address of a is 0xd38450 top of "..., 62address of a is 0xd38450 top of heap after malloc is 0xd72000) = 62
write(1, "address of a is 0xd51460 top of "..., 62address of a is 0xd51460 top of heap after malloc is 0xd72000) = 62
brk(0xda4000) = 0xda4000 // 同样通过移动堆顶分配内存
write(1, "address of a is 0xd6a470 top of "..., 62address of a is 0xd6a470 top of heap after malloc is 0xda4000) = 62
write(1, "address of a is 0xd83480 top of "..., 62address of a is 0xd83480 top of heap after malloc is 0xda4000) = 62
brk(0xdd6000) = 0xdd6000 // 同样通过移动堆顶分配内存
write(1, "address of a is 0xd9c490 top of "..., 62address of a is 0xd9c490 top of heap after malloc is 0xdd6000) = 62
write(1, "address of a is 0xdb54a0 top of "..., 62address of a is 0xdb54a0 top of heap after malloc is 0xdd6000) = 62
brk(0xe08000) = 0xe08000 // 同样通过移动堆顶分配内存
write(1, "address of a is 0xdce4b0 top of "..., 62address of a is 0xdce4b0 top of heap after malloc is 0xe08000) = 62
//用mmap在文件映射区为进程分配内存
mmap(NULL, 1052672, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f0cd5140000
write(1, "malloc end\n", 11malloc end) = 11
write(1, "before free, the top of heap is "..., 41before free, the top of heap is 0xe08000) = 41
brk(0xd0e000) = 0xd0e000 //释放通过brk移动堆顶分配的内存
write(1, "after free, the top of heap is "..., 41after free, the top of heap is 0xd0e000) = 41
munmap(0x7f0cd5140000, 1052672) = 0 //释放mmap分配的内存
exit_group(0) = ?
+++ exited with 0 +++