Aspects


vs


Malloc

The malloc function performs dynamic memory allocation in C and is part of the standard library

Realloc

C library function for reallocating a dynamically allocated memory region.

Faster memcpy memory

Quality Example
More memory

"That s why realloc can temporarily require more memory than a malloc free pair"

from question "Why is realloc eating tons of memory?"

Faster

"A realloc can occur significantly faster than a malloc memcpy and free"

from question "Why is there no reallocation functionality in C++ allocators?"

Others

Quality Example
More

"But if it works with large datasets the users will notice that using the malloc -only program slows down other programs much more than the realloc -using program with the same data"

from question "Why should we use `realloc` if we need a `tmp buffer`"

Often more

"Malloc often gives you more memory that you ask and stores the actual value in a special location that realloc can access at a later time"

from question "Realloc simply not diong anything, not erroring"

Less

"In the case of overflow a free malloc pair costs less than realloc because of its internal hidden memcpy"

from question "Substitute or workaround for asprintf on AIX"

Faster 2nd

"The justification of realloc is that it s faster than 2nd malloc manual copy free"

from question "C++ realloc performance vs malloc"

Worse

"Realloc is worse than malloc in that you will need to have the old and new pointers valid during the realloc"

from question "Is realloc() safe in embedded system?"

Way smarter

"I mean i think realloc is way smarter so why do we even need malloc"

from question "Why am I getting a segmentation fault when using realloc()?"

Back to Home
Data comes from Stack Exchange with CC-BY-SA-3.0