-3

calloc function used to reserve memory and gives starting address of memory block but it is said that it may not allocate in contiguous address space and rather it my allocate different different non contiguous blocks but starting address we get as return value of calloc will only point to contiguous memory from starting address then if memory is allocated with two memory block then how pointer will jump to other memory block when one contiguous block will be occupied

void * calloc (size_t n, size_t size)
Emil Laine
  • 41,598
  • 9
  • 101
  • 157

2 Answers2

2

but it is said that it may not allocate in contiguous address space

Where is this "said" and what's the context?

calloc() returns a pointer to a contiguous block (in virtual address space) of size nelem * size.

Consecutive calls to calloc() don't give you adjacent blocks (in general).

  • hey bro search in internet you will find that calloc gives non contiguous blocks of memory and it uses linked list for that and here i am talking about logical address only (calloc will assigned blocks of non contiguous logical address . – Niravsinh Parmar Oct 28 '15 at 14:40
  • Go to the site given below and see your self in side is is given that calloc may or may not give contiguous locations ..... http://r4r.co.in/answer/index.php?id=22&option=C%20SUB – Niravsinh Parmar Nov 05 '15 at 18:56
  • here is one other where it is mentioned that may or may not continuous http://www.cprogrammingexpert.com/C/Tutorial/dynamic_memmory_allocation/calloc.aspx – Niravsinh Parmar Nov 05 '15 at 19:04
0

Where did you read that:

it my allocate different different non contiguous blocks but starting address > we get as return value of calloc will only point to contiguous memory from starting address

The C library function void *calloc(size_t nitems, size_t size) allocates the requested memory and returns a pointer to it. The difference in malloc and calloc is that malloc does not set the memory to zero where as calloc sets allocated memory to zero.

http://en.cppreference.com/w/c/memory/calloc

Alex Lop.
  • 6,810
  • 1
  • 26
  • 45