As per:
calloc(20, sizeof(int))
malloc(20 * sizeof(int))
Which will allocate memory for the 20 integers.
Does malloc()
& calloc()
allocates virtual or physically continuous space?
C doesn't say that the machine has both physical and virtual address space.
All you know is that you get pointers, and that you can index/dereference them in a continuous fashion as defined by the language's operators.
If doing so requires the hardware to re-map virtual addresses to physical ones, or send e-mail to someone who replies with the content of the addressed location, is implementation-defined.
Whether the space is physically continuous or not depends on the platform you are developing on, the MMU and the OS....
Virtually it will be continuous, always.
Whether it is calloc or malloc will not make a difference.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With