Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

calloc vs malloc

Status
Not open for further replies.

svar

Programmer
Aug 12, 2001
349
GR
Just to check I understand this right:
calloc says : I want a chunk of memory of this size AND it has to be contiguous(consecutive memory locations)
malloc says: I need this memory and I don't care where
you find it and if it's contiguous or not
realloc says: I need to change a previous calloced memory
and it still needs to be contiguous and if the originally allocated memory cannot be expanded, it should try to find a different contiguous memory of the requested size AND
copy the originally allocated data to the new memory block

Is that basically right?
 
C RTL malloc() never said about non-contiguous memory chunk. It's a nonsense. Many years ago IBM OS/360 have had a macros with non-contiguos memory request. It's a hystory...
C RTL calloc() fills malloc'ed memory chunk with zeroes.
C RTL realloc() needs previously malloc'ed (not specifically calloc'ed) pointer.
That's all...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top