next up previous
Next: Further references Up: Frequently Asked Questions Previous: What about cleaning up

Why is realloc not supported?

The main reason is that realloc() is rarely used in C programs. Since the cost of implementing such an operator is not negligible, I'd prefer to avoid it altogether.

There are also some portability problems. Some platforms do not allow reallocation of a NULL pointer, which is sometimes useful to allocate growing lists without programming the first iteration specifically. To keep your program portable, do not use this feature. Another use of realloc is to free() a pointer, this is also not uniformly implemented.

It seems that the realloc() implementation is simply doing a malloc+memcpy on many platforms. See with your C library implementation, but the general perception in the C programming community is that this function is very often implemented as an alias for "allocate and copy".

Anyway, a realloc() call could be implemented in this module if the need arises. It is just that most module users could live without it until now, at least.

Nicolas Devillard 2002-05-03