What is the difference between xmalloc()
and malloc()
for memory allocation?
Is there any pro of using xmalloc()
?
xmalloc()
is a non-standard function that has the motto succeed or die. If it fails to allocate memory, it will terminate your program and print an error message to stderr
.
The allocation itself is no different; only the behaviour in the case that no memory could be allocated is different.
Use malloc()
, since it's more friendly and standard.