Is the memory allocated by malloc not necessarily physically continous?

1.4k Views Asked by At

the memory allocated by malloc could occupy several pages and these pages are not necessarily next to each other, is this correct?

3

There are 3 best solutions below

0
On

That is correct.

Physically contiguous memory only matters for DMA and you don't care because you are not in kernel space.

It will be contiguous in virtual address space.

0
On

Yes, physically they are not guaranteed to be adjacent, but at least in the process' virtual address space they will appear to be.

In userspace you rarely have to think about physical memory and contiguous pages.

0
On

malloc will give you memory thats continous on the virtual address space. If you know how virtual memory works, you know that there are no guarantees that virtual pages are physically continous.