malloc分配的内存都是连续的么?
`
简短回答:是的(连续的虚拟内存,但无法保证是连续的物理内存)
malloc will fail if there isn’t a large enough contiguous block available. (A failure with malloc will return a NULL pointer)
malloc() doesn’t know or care about physical memory. No user-space program does. Only the operating system kernel knows the mapping between virtual and physical pages.
As a user-space program you have no control over physical pages. If a user-space program requests a 1GB allocation from the operating system, the result will be 1GB of contiguous virtual memory, but the individual physical pages used to satisfy that request have no requirement whatsoever. They can be a random patchwork of pages from all over the place. User-space does not know or care. This is the case regardless of the scenario, so in your example there was no guarantee that your initial eight allocations used contiguous physical pages, which it almost certainly did not.
`
https://stackoverflow.com/questions/625270/does-malloc-allocate-a-contiguous-block-of-memory
https://linux.die.net/man/3/malloc
https://www.reddit.com/r/C_Programming/comments/4t1qvz/does_malloc_allocate_contiguous_physical_memory/